Enhanced Sun component

latest 0.88.1

My guess is that you did not copy sun.py from my github correctly – e.g., you didn’t use the Raw button and instead of getting the actual code you got an html page.

that’s the content of the file

Hmm. That error only happens if the file does not contain either async_setup or setup, and it definitely has the former.

So the header of that snippet says the file’s name is sun.py. I thought you moved/renamed it to __init__.py. You should have only these (for the custom sun component):

custom_components/sun/__init__.py  <-- This is sun.py from my github
custom_components/sun/automation.py

There should be no:

custom_components/sun.py
1 Like

thank you for your clarification, cleaned up all the files
it’s now working

1 Like

@DavidFW1960, @klogg, et al,

Let’s try something different to get around the issue where hassio won’t let you create a symbolic link. Try this instead. After moving/renaming my sun.py to custom_components/sun/__init__.py, add a new custom_components/sun/automation.py with this one line content:

from homeassistant.components.automation.sun import *

Seems to work in my testing.

@ludeeus,

Does the custom updater support a custom component that consists of more than one file? E.g., in this case it looks like I’ll need these two:

custom_components/sun/__init__.py
custom_components/sun/automation.py

If so, what do I need to do with my json file?

Currently no, but I will look into it in the future.

Well, given the great migration, that may be needed sooner rather than later! Ha! :slight_smile:

In the meantime, would I need to effectively create two custom components (sun & sun.automation), and people would have to know to install both (per my instructions)? Would that work do you think?

FWIW, I think I might know why the warning about using a custom component for sun is not being seen on the Info page – I think the warning is being generated before the logging system is completely initialized:

2019-02-24 10:02:39 WARNING (MainThread) [homeassistant.loader] You are using a custom component for sun which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-02-24 10:02:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=logger, service=set_default_level>
2019-02-24 10:02:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=logger, service=set_level>
2019-02-24 10:02:39 INFO (MainThread) [homeassistant.setup] Setup of domain logger took 0.0 seconds.
2019-02-24 10:02:39 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=logger>

That should work, but it’s bad :confused:

I think I can have some logic for it within 2days

FWIW, I just updated my json file and other files on github, including docs, to be consistent with the new layout (and how to use with versions of HA before 0.86.) This includes adding a “sun.automation” element. That will bridge the gap until you have something working.

BTW, I’ve meant to mention this before, but in pyupdate’s install methods, it probably shouldn’t be creating directories based on the element name, but rather on the local path. You might want to look at that.

Thanks for the feedback!, that has now changed.

with the newest updater you can add extra resources in a resources key, NB: This only works if the component locally will be named __init__.py since it will download to the same dir as that.
example

  "sun": {
    "updated_at": "2019-02-19",
    "version": "1.1.0",
    "local_location": "/custom_components/sun/__init__.py",
    "remote_location": "https://raw.githubusercontent.com/pnbruckner/homeassistant-config/master/custom_components/sun/__init__.py",
    "visit_repo": "https://github.com/pnbruckner/homeassistant-config",
    "changelog": "https://github.com/pnbruckner/homeassistant-config/blob/master/docs/sun.md#release-notes",
    "resources": [
      "https://raw.githubusercontent.com/pnbruckner/homeassistant-config/master/custom_components/sun/automation.py"
    ]
  }

Thanks. I’ll update accordingly.

Made your suggested changes Phil and it’s still working/not broken…

1 Like

I updated the sun component to the new structure and when I restarted I noticed my tracker card was gone. No errors in the log tho so that was strange.

I reverted everything back to the old structure and still had no tracker card.

I ended up having to comment out your update entry in the custom_updater and the tracker card came back.

then just to verify I put everything back to the new structure and the tracker card is still ok. So it looks like there is something in your github that the custom_updater/tracker card doesn’t like.

edit: I added your URL back in to the custom_updater again, the tracker is gone again and now I get this in the log:

2019-02-25 06:42:33 ERROR (MainThread) [frontend.js.latest.201902030] http://192.168.1.11:8123/customcards/lovelace/tracker-card.js:201:54 Uncaught TypeError: Cannot read property 'addEventListener' of null

I don’t know if that’s your problem or the custom_updater problem but I updated the custom_updater and it’s still erroring out.

First, I made a major update along these lines around 2019-02-24 17:00:00 UTC (i.e., yesterday at 11:00 AM CST.) The layout of my github was changed to correspond to the new layout, and I updated the instructions and the JSON files accordingly. So it’s possible if you did this while the custom updater’s copy of the JSON file was old, this might have caused problems. (It would have been pointing to where files were, but were not anymore.) You might want to try again if this was possibly the case (its copy should have updated by now.)

If that’s not the issue, then you need to take this up with @ludeeus, or file an issue on the custom_updater’s issue page.

Also, FYI, I haven’t made the change suggested above to combine sun/__init__.py and sun.automation.py into one custom_updater “element”. For now you need to install both “sun” and “sun.automation”.

the tracker card is working now but your sun.sun component isn’t in the list anymore.

And I did put in both files into the custom_components/sun/ directory.

Sorry, I’m confused. “sun.sun” should never have been in the list, only “sun”. Is that what you meant?

What is you custom_updater config now? And what version of HA are you running?

yeah, sorry, i didn’t remember what exactly it said before. I just knew it was there before and now it isn’t.

- https://raw.githubusercontent.com/pnbruckner/homeassistant-config/master/custom_components.json

v87.0