Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import Errors on first run #1

Closed
cameronclans opened this issue Jan 25, 2024 · 20 comments
Closed

Import Errors on first run #1

cameronclans opened this issue Jan 25, 2024 · 20 comments

Comments

@cameronclans
Copy link

cameronclans commented Jan 25, 2024

Firstly thank you for your efforts - the idea of this is amazing for an Octopus/Powerwall user.

Home Assistant - Fresh install with default integrations
HACS - Fresh install

  • Octopus Energy - Fresh install, 2 devices 41 entities all working correctly
  • PyScript - Fresh install

config/configuration.yaml:

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
pyscript: !include pyscript/config.yaml

I added an include after trying the config in the config/configuration.yaml without success

config/pyscript/config.yaml:

allow_all_imports: true #tried with and without this
hass_is_global: true #tried with and without this
apps:
  powerwall:
      email: **MYEMAIL**
      refresh_token: **MYTOKEN**
      tariff_name: Agile
      tariff_provider: Octopus
      import_mpan: **MYMPAN**
      tariff_breaks: [0.10, 0.20, 0.30]
      tariff_pricing: ["average", "average", "maximum", "maximum"]
      plunge_pricing_tariff_breaks: [0.0, 0.10, 0.30]

My errors are:

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun home-assistant (no readiness notification)
s6-rc: info: service legacy-services successfully started
2024-01-25 16:54:04.318 WARNING (SyncWorker_4) [homeassistant.loader] We found a custom integration octopus_energy which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-01-25 16:54:04.318 WARNING (SyncWorker_4) [homeassistant.loader] We found a custom integration hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-01-25 16:54:04.318 WARNING (SyncWorker_4) [homeassistant.loader] We found a custom integration pyscript which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-01-25 16:54:07.602 ERROR (MainThread) [custom_components.pyscript.file.__init__] Exception in </config/pyscript/__init__.py> line 31:
    from .const import (
    ^
ImportError: attempted relative import with no known parent package
2024-01-25 16:54:07.603 ERROR (MainThread) [custom_components.pyscript.file.config_flow] Exception in </config/pyscript/config_flow.py> line 11:
    from .const import CONF_ALLOW_ALL_IMPORTS, CONF_HASS_IS_GLOBAL, CONF_INSTALLED_PACKAGES, DOMAIN
    ^
ImportError: attempted relative import with no known parent package
2024-01-25 16:54:07.605 ERROR (MainThread) [custom_components.pyscript.file.entity] Exception in </config/pyscript/entity.py> line 10:
        _attr_extra_state_attributes: dict
�������
^
NotImplementedError: file.entity: not implemented ast ast_annassign
2024-01-25 16:54:07.623 ERROR (MainThread) [custom_components.pyscript.file.eval] Exception in </config/pyscript/eval.py> line 22:
    from .const import (
    ^
ImportError: attempted relative import with no known parent package
2024-01-25 16:54:07.624 ERROR (MainThread) [custom_components.pyscript.file.event] Exception in </config/pyscript/event.py> line 5:
    from .const import LOGGER_PATH
    ^
ImportError: attempted relative import with no known parent package
2024-01-25 16:54:07.628 ERROR (MainThread) [custom_components.pyscript.file.function] Exception in </config/pyscript/function.py> line 9:
    from .const import LOGGER_PATH, SERVICE_RESPONSE_NONE, SERVICE_RESPONSE_ONLY
    ^
ImportError: attempted relative import with no known parent package
2024-01-25 16:54:07.630 ERROR (MainThread) [custom_components.pyscript.file.global_ctx] Exception in </config/pyscript/global_ctx.py> line 10:
    from .const import CONF_HASS_IS_GLOBAL, CONFIG_ENTRY, DOMAIN, FOLDER, LOGGER_PATH
    ^
ImportError: attempted relative import with no known parent package
2024-01-25 16:54:07.637 ERROR (MainThread) [custom_components.pyscript.file.jupyter_kernel] Exception in </config/pyscript/jupyter_kernel.py> line 22:
    from .const import LOGGER_PATH
    ^
ImportError: attempted relative import with no known parent package
2024-01-25 16:54:07.638 ERROR (MainThread) [custom_components.pyscript.file.logbook] Exception in </config/pyscript/logbook.py> line 6:
    from .const import DOMAIN
    ^
ImportError: attempted relative import with no known parent package
2024-01-25 16:54:07.639 ERROR (MainThread) [custom_components.pyscript.file.mqtt] Exception in </config/pyscript/mqtt.py> line 8:
    from .const import LOGGER_PATH
    ^
ImportError: attempted relative import with no known parent package
2024-01-25 16:54:07.641 ERROR (MainThread) [custom_components.pyscript.file.requirements] Exception in </config/pyscript/requirements.py> line 12:
    from .const import (
    ^
ImportError: attempted relative import with no known parent package
2024-01-25 16:54:07.776 ERROR (MainThread) [custom_components.pyscript.file.state] Exception in </config/pyscript/state.py> line 10:
    from .const import LOGGER_PATH
    ^
ImportError: attempted relative import with no known parent package
2024-01-25 16:54:07.790 ERROR (MainThread) [custom_components.pyscript.file.trigger] Exception in </config/pyscript/trigger.py> line 17:
    from .const import LOGGER_PATH
    ^
ImportError: attempted relative import with no known parent package

Any assistance greatly appreciated

@pulquero
Copy link
Owner

So, I have it organised like this:
config/configuration.yaml:

.
.
.
pyscript: !include pyscript.yaml

config/pyscript.yaml has my config in. Then config/pyscript/apps/powerwall/* and config/pyscript/modules/* with the code in.

Maybe, try placing your config outside the config/pyscript directory. I don't know if the presence of a yaml file there might upset the python interpreter (maybe it upsets how it detects packages). That would be my first thing to try.

Funnily enough, I have encountered relative import errors before when trying to organise my scripts, never got to the bottom of it, only that the current organisation in config/pyscript/modules gets round it. However, your errors are from pyscript itself, but maybe this does suggest some file (eg config) is in the wrong place.

@cameronclans
Copy link
Author

cameronclans commented Jan 25, 2024

That appears to have done it thank you - moving the config up to config/ did the trick and I now see:

apps_powerwall_refresh_next_day_rates has been triggered by event octopus_energy_electricity_next_day_rates
22:40:22 - 4 minutes ago
apps_powerwall_refresh_current_day_rates has been triggered by event octopus_energy_electricity_current_day_rates
22:40:22 - 4 minutes ago
apps_powerwall_refresh_previous_day_rates has been triggered by event octopus_energy_electricity_previous_day_rates
22:40:22 - 4 minutes ago

In the HA logs which appears good on the surface.

Are you aware of any way to see responses/output from the powerwall update as these are not yet updated in the Tesla app?

@pulquero
Copy link
Owner

The utility rate plan info in the app should update.

@pulquero
Copy link
Owner

Btw, do you have an export mpan? I haven't added export rates yet, as I'm still waiting on paper work so have nothing to test with.

@cameronclans
Copy link
Author

As of 05:30 this morning the utility rate pricing and schedule have still not updated. Some key info below, please let me know if you'd rather I log a new issue for posterity:

  • I had a plan configured in the Tesla app already named under my old utility plan "'Flux"
  • I updated this manually last night to rename it to Agile
  • peak, mid-peak and off-peak pricing remain as they did when I manually set them months ago
  • peak, mid-peak and off-peak timings remain as they did when I manually set them months ago
  • At approx 0800 UTC yesterday, my powerwall was updated to firmware version 23.44.0
  • I do have an export MPAN and tariff

Thanks a lot for your continued help

@pulquero
Copy link
Owner

No errors in HA under system logs? One thing that comes to mind is I had issues with the release version of teslapy. I had to place a copy of head under config/pyscript_packages. I also renamed the directory from teslapy to teslapy_latest and updated the imports to teslapy_latest to guarantee that version was being used.

Yeah, just checked, last release is still from May.

@cameronclans
Copy link
Author

No errors under HA logs (with or without debug on pyscripts) however, I did not manually install teslapy (though there's a teslapy_wrapper.py under config/pyscript/modules/).

Is this something that I should've installed separately? If so, I'd update the readme which currently says:

Installation

1. Install Home Assistant Octopus Energy integration.
2. Install Pyscript integration.
3. Copy the contents of the src directory to the Home Assistant directory /config/pyscript.
4. Add Pyscript app configuration:

@pulquero
Copy link
Owner

There is a requirements.txt which pyscript should read and process. The corresponding pip install should be visible in the log. Hmmm, maybe that i changed the log level using the log service call to see it.

@cameronclans
Copy link
Author

This could be an error/lack of knowledge on my part, I'll do a quick recce now that I understand that part of the process.
The requirements.txt is there and populated as you describe.

@cameronclans
Copy link
Author

cameronclans commented Jan 26, 2024

Getting nearer - I spotted an issue with one of the other requirements in the debug logs:

2024-01-26 09:55:36.738 DEBUG (SyncWorker_4) [custom_components.pyscript] Ignoring ''urllib3<2'' because it is not a valid package
2024-01-26 09:55:36.745 DEBUG (MainThread) [custom_components.pyscript] Skipping unpinned version of package 'teslapy' because version '2.8.0' is already installed
2024-01-26 09:55:36.745 DEBUG (MainThread) [custom_components.pyscript] No new packages to install
2024-01-26 09:55:36.863 DEBUG (MainThread) [custom_components.pyscript.eval] modules.powerwall_tariff: calling timedelta(, {'days': 1})
2024-01-26 09:55:36.866 INFO (MainThread) [custom_components.pyscript.global_ctx] Loaded /config/pyscript/modules/powerwall_tariff.py

@pulquero
Copy link
Owner

Do you still have allow_all_imports: true?

@cameronclans
Copy link
Author

I do:

    allow_all_imports: true 
    hass_is_global: true 
    apps:
        powerwall:
...etc etc

I checked that it was there (is_global is too as you can see, I assume that's ok?!)

Latest logs are the same after config check and restart:

2024-01-26 10:23:11.530 DEBUG (SyncWorker_2) [custom_components.pyscript] Ignoring ''urllib3<2'' because it is not a valid package
2024-01-26 10:23:11.552 DEBUG (MainThread) [custom_components.pyscript] Skipping unpinned version of package 'teslapy' because version '2.8.0' is already installed
2024-01-26 10:23:11.552 DEBUG (MainThread) [custom_components.pyscript] No new packages to install

@cameronclans
Copy link
Author

pip list from within the container shows both TeslaPy (2.8.0) and urllib3 (1.26.18) if that's worth anything

@pulquero
Copy link
Owner

Seems like it has sort of worked then. Try replacing 'urllib3<2' with urllib3==1.26.18
(no single quotes).

@cameronclans
Copy link
Author

It looks much happier with that in the DEBUG logs:

2024-01-26 10:53:52.439 DEBUG (MainThread) [custom_components.pyscript] Skipping unpinned version of package 'teslapy' because version '2.8.0' is already installed
2024-01-26 10:53:52.440 DEBUG (MainThread) [custom_components.pyscript] Version '1.26.18' for package 'urllib3' detected in '['/config/pyscript/apps/powerwall/requirements.txt']' will be ignored because it is already installed
2024-01-26 10:53:52.440 DEBUG (MainThread) [custom_components.pyscript] No new packages to install
2024-01-26 10:53:52.725 DEBUG (MainThread) [custom_components.pyscript.eval] modules.powerwall_tariff: calling timedelta(, {'days': 1})
2024-01-26 10:53:52.728 INFO (MainThread) [custom_components.pyscript.global_ctx] Loaded /config/pyscript/modules/powerwall_tariff.py
2024-01-26 10:53:52.771 INFO (MainThread) [custom_components.pyscript.global_ctx] Loaded /config/pyscript/modules/teslapy_wrapper.py
2024-01-26 10:53:52.771 DEBUG (MainThread) [custom_components.pyscript.eval] apps.powerwall: calling Rates(, {})
2024-01-26 10:53:52.773 INFO (MainThread) [custom_components.pyscript.global_ctx] Reloaded /config/pyscript/apps/powerwall/__init__.py
2024-01-26 10:53:53.646 DEBUG (MainThread) [custom_components.pyscript] adding state changed listener and starting global contexts
2024-01-26 10:53:53.663 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger apps.powerwall.refresh_previous_day_rates is active
2024-01-26 10:53:53.663 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger apps.powerwall.refresh_current_day_rates is active
2024-01-26 10:53:53.663 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger apps.powerwall.refresh_next_day_rates is active
2024-01-26 10:53:53.668 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger apps.powerwall.refresh_previous_day_rates adding event_trigger octopus_energy_electricity_previous_day_rates
2024-01-26 10:53:53.668 DEBUG (MainThread) [custom_components.pyscript.event] event.notify_add(octopus_energy_electricity_previous_day_rates) -> adding event listener
2024-01-26 10:53:53.668 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger apps.powerwall.refresh_previous_day_rates waiting for state change or event
2024-01-26 10:53:53.668 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger apps.powerwall.refresh_current_day_rates adding event_trigger octopus_energy_electricity_current_day_rates
2024-01-26 10:53:53.668 DEBUG (MainThread) [custom_components.pyscript.event] event.notify_add(octopus_energy_electricity_current_day_rates) -> adding event listener
2024-01-26 10:53:53.668 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger apps.powerwall.refresh_current_day_rates waiting for state change or event
2024-01-26 10:53:53.668 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger apps.powerwall.refresh_next_day_rates adding event_trigger octopus_energy_electricity_next_day_rates
2024-01-26 10:53:53.668 DEBUG (MainThread) [custom_components.pyscript.event] event.notify_add(octopus_energy_electricity_next_day_rates) -> adding event listener
2024-01-26 10:53:53.668 DEBUG (MainThread) [custom_components.pyscript.trigger] trigger apps.powerwall.refresh_next_day_rates waiting for state change or event

Is there any indication of how long it should take to update the Powerwalls utility plan settings? I'll leave it running for a few hours now and check the logs when I can.

LMK if I can buy you a coffee/beer or support the project...once it's up and working it'll be invaluable to me and I'm sure many others.

@pulquero
Copy link
Owner

Cool, I'll make that change in head then. I can also add a log statement when the tariff info is pushed to pw. It should happen immediately once the previous/current/next rates have been retrieved.

@cameronclans
Copy link
Author

It's grabbed all the latest rates but for one reason or another it's not updated the pw yet.
Checking the logs, I see plenty of triggers for Octopus rates and apps.powerwall but nothing for teslapy apart from it loading the teslapy wrapper.
Sharing this info in case it's indicative of something or other

@pulquero
Copy link
Owner

There is a debug line for tariff data just before it updates the pw (

debug(f"Tariff data:\n{tariff_data}")
)
check for that in the log, and to avoid messing around with log levels, can change the debug function to log to info:

def debug(msg):
    log.info(msg)

Also, try the head version of teslapy (see #1 (comment)).

@cameronclans
Copy link
Author

cameronclans commented Jan 26, 2024

Thanks, it's still not updating (nothing in the log to say it's attempting/failing) and I'm about to be travelling for a few hours so I'll leave it running and then when I get back tonight I shall check again and try the head version. I'll log a new issue if required as the original is certainly resolved. (lmk about that project support/coffee/beer).

@pulquero
Copy link
Owner

No problem, project support would be much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants