-
-
Notifications
You must be signed in to change notification settings - Fork 38.3k
SMA: Optional import in schema & backoff fix #18099
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -35,7 +35,10 @@ | |||||
|
|
||||||
| def _check_sensor_schema(conf): | ||||||
| """Check sensors and attributes are valid.""" | ||||||
| import pysma | ||||||
| try: | ||||||
| import pysma | ||||||
| except ImportError: | ||||||
| return conf | ||||||
|
|
||||||
| valid = list(conf[CONF_CUSTOM].keys()) | ||||||
| valid.extend([s.name for s in pysma.SENSORS]) | ||||||
|
|
@@ -73,6 +76,9 @@ async def async_setup_platform( | |||||
| """Set up SMA WebConnect sensor.""" | ||||||
| import pysma | ||||||
|
|
||||||
| # Check config again during load - dependancy available | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's try this 'suggested change' feature 😉
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @tjorim ! I fixed this on Friday, but could not push due to issues on github. I pushed my fixes now
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This suggested change feature looks quite cool though! |
||||||
| config = _check_sensor_schema(config) | ||||||
|
|
||||||
| # Sensor_defs from the custom config | ||||||
| for name, prop in config[CONF_CUSTOM].items(): | ||||||
| n_s = pysma.Sensor(name, prop['key'], prop['unit'], prop['factor']) | ||||||
|
|
@@ -107,18 +113,24 @@ async def async_close_session(event): | |||||
| hass.bus.async_listen(EVENT_HOMEASSISTANT_STOP, async_close_session) | ||||||
|
|
||||||
| backoff = 0 | ||||||
| backoff_step = 0 | ||||||
|
|
||||||
| async def async_sma(event): | ||||||
| """Update all the SMA sensors.""" | ||||||
| nonlocal backoff | ||||||
| nonlocal backoff, backoff_step | ||||||
| if backoff > 1: | ||||||
| backoff -= 1 | ||||||
| return | ||||||
|
|
||||||
| values = await sma.read(used_sensors) | ||||||
| if values is None: | ||||||
| backoff = 10 | ||||||
| if not values: | ||||||
| try: | ||||||
| backoff = [1, 1, 1, 6, 6, 6, 30, 30][backoff_step] | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks ok. I would probably instead use a start value that is multiplied and cap it with min and max values. The value would represent the time until next try. Eg: But maybe we need a different approach here? You know the integration best.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let’s keep this. I will change to 1,1,1,6,30 and end with the 60 Reasoning The library is fairly resilient and that why I have the many 1xS_I to start. If something goes wrong (a) might be network based or (b) not sure about the exact timeout when the user will be available(might have logged in through browser etc) |
||||||
| backoff_step += 1 | ||||||
| except IndexError: | ||||||
| backoff = 60 | ||||||
| return | ||||||
| backoff_step = 0 | ||||||
|
|
||||||
| tasks = [] | ||||||
| for sensor in hass_sensors: | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.