-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Improvements for WeMo Insight switches #6001
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 9 commits
29c7987
c404fb7
44d274e
a718e92
b163544
e221c8a
e9cf5f6
f6e46ae
ef87d4d
fc5e25a
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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| https://home-assistant.io/components/switch.wemo/ | ||
| """ | ||
| import logging | ||
| from datetime import datetime, timedelta | ||
|
|
||
| from homeassistant.components.switch import SwitchDevice | ||
| from homeassistant.const import ( | ||
|
|
@@ -109,12 +110,33 @@ def device_state_attributes(self): | |
|
|
||
| if self.insight_params or (self.coffeemaker_mode is not None): | ||
| attr[ATTR_CURRENT_STATE_DETAIL] = self.detail_state | ||
| attr['current_power_w'] = \ | ||
|
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. This is just the existing switch attribute divided by 1000. At some point we'll change the switch attribute to be My suggestion would be to remove it |
||
| self.insight_params['currentpower'] / 1000 | ||
| attr['today_power_mW_min'] = self.insight_params['todaymw'] | ||
| attr['total_power_mW_min'] = self.insight_params['totalmw'] | ||
|
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. This line is duplicated - but it's also a duplicate of the existing
Contributor
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. Will remove in favour of the incorrectly labeled existing ones |
||
| attr['on_time_most_recent'] = \ | ||
| WemoSwitch.as_uptime(self.insight_params['onfor']) | ||
| attr['on_time_today'] = \ | ||
| WemoSwitch.as_uptime(self.insight_params['ontoday']) | ||
| attr['on_time_total'] = \ | ||
| WemoSwitch.as_uptime(self.insight_params['ontotal']) | ||
| attr['power_threshold_w'] = \ | ||
| self.insight_params['powerthreshold'] / 1000 | ||
|
|
||
| if self.coffeemaker_mode is not None: | ||
| attr[ATTR_COFFEMAKER_MODE] = self.coffeemaker_mode | ||
|
|
||
| return attr | ||
|
|
||
| @staticmethod | ||
| def as_uptime(_seconds): | ||
| """Format seconds into uptime string in the format: 00d 00h 00m 00s.""" | ||
| uptime = datetime(1, 1, 1) + timedelta(seconds=_seconds) | ||
| return "{:0>2d}d {:0>2d}h {:0>2d}m {:0>2d}s".format(uptime.day-1, | ||
|
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. Why not use the timedelta object directly? It supports days, hours etc https://docs.python.org/3/library/datetime.html#datetime.timedelta
Contributor
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. I'm probably doing something stupid (python noob), but when I try that I get this:
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. Oh you're right, I was wrong. Looks like timedelta converts it all to seconds. |
||
| uptime.hour, | ||
| uptime.minute, | ||
| uptime.second) | ||
|
|
||
| @property | ||
| def current_power_mwh(self): | ||
| """Current power usage in mWh.""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't expect the coffee machine will support these new attributes - so I'd change this so that you only retrieve these attributes for the insight device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call