-
-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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 3 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 ( | ||
|
|
@@ -20,6 +21,16 @@ | |
| ATTR_CURRENT_STATE_DETAIL = 'state_detail' | ||
| ATTR_COFFEMAKER_MODE = "coffeemaker_mode" | ||
|
|
||
| # Wemo Insight | ||
| ATTR_POWER_CURRENT_W = 'power_current_w' | ||
| # ATTR_POWER_AVG_W = 'power_average_w' | ||
| ATTR_POWER_TODAY_MW_MIN = 'power_today_mW_min' | ||
| ATTR_POWER_TOTAL_MW_MIN = 'power_total_mW_min' | ||
| ATTR_ON_FOR_TIME = 'on_time_most_recent' | ||
| ATTR_ON_TODAY_TIME = 'on_time_today' | ||
| ATTR_ON_TOTAL_TIME = 'on_time_total' | ||
| ATTR_POWER_THRESHOLD = 'power_threshold_w' | ||
|
|
||
| MAKER_SWITCH_MOMENTARY = "momentary" | ||
| MAKER_SWITCH_TOGGLE = "toggle" | ||
|
|
||
|
|
@@ -109,23 +120,82 @@ 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[ATTR_POWER_CURRENT_W] = self.power_current_watt | ||
| # attr[ATTR_POWER_AVG_W] = self.power_average_watt | ||
| attr[ATTR_POWER_TODAY_MW_MIN] = self.power_today_mw_min | ||
| attr[ATTR_POWER_TOTAL_MW_MIN] = self.power_total_mw_min | ||
| attr[ATTR_ON_FOR_TIME] = self.on_for | ||
| attr[ATTR_ON_TODAY_TIME] = self.on_today | ||
| attr[ATTR_ON_TOTAL_TIME] = self.on_total | ||
| attr[ATTR_POWER_THRESHOLD] = self.power_threshold | ||
|
|
||
| if self.coffeemaker_mode is not None: | ||
| attr[ATTR_COFFEMAKER_MODE] = self.coffeemaker_mode | ||
|
|
||
| return attr | ||
|
|
||
| # @property | ||
|
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. Stale comment ?
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. Yeah, not needed, was from originally when that method was currrent_power_mwh |
||
| def _current_power_mw(self): | ||
| """Current power usage in mW.""" | ||
| if self.insight_params: | ||
| return self.insight_params['currentpower'] | ||
|
|
||
| @property | ||
| def power_current_watt(self): | ||
| """Current power usage in W.""" | ||
| if self.insight_params: | ||
| try: | ||
| return self._current_power_mw() / 1000 | ||
| except: | ||
| return None | ||
|
|
||
| @property | ||
|
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 are somethings properties and other methods ? Also, why are they properties/method to begin with and not just all part of
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. Started out cutting and pasting what was there (I'm not a python guy, nor do I know HA components)... If we don't need the methods, I can just load everything into the state attribs assignments. |
||
| def power_threshold(self): | ||
| if self.insight_params: | ||
| return self.insight_params['powerthreshold'] / 1000 | ||
|
|
||
| def _as_uptime(self, _seconds): | ||
| d = datetime(1,1,1) + timedelta(seconds=_seconds) | ||
|
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. indentation is not a multiple of four |
||
| return "{:0>2d}d {:0>2d}h {:0>2d}m {:0>2d}s".format(d.day-1, | ||
|
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. indentation is not a multiple of four |
||
| d.hour, | ||
| d.minute, | ||
|
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. trailing whitespace |
||
| d.second) | ||
|
|
||
|
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. blank line contains whitespace |
||
| @property | ||
| def on_for(self): | ||
| """On time in seconds.""" | ||
| if self.insight_params: | ||
| return self._as_uptime(self.insight_params['onfor']) | ||
|
|
||
| @property | ||
| def on_today(self): | ||
| """On time in seconds.""" | ||
| if self.insight_params: | ||
| return self._as_uptime(self.insight_params['ontoday']) | ||
|
|
||
| @property | ||
| def on_total(self): | ||
| """On time in seconds.""" | ||
| if self.insight_params: | ||
| return self._as_uptime(self.insight_params['ontotal']) | ||
|
|
||
| @property | ||
| def current_power_mwh(self): | ||
| """Current power usage in mWh.""" | ||
| def power_total_mw_min(self): | ||
|
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. You can't just rename overrides of official properties. Please check out the switch ABC and see what is supported and what is not.
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. The Insight returns average milliwatt power consumed for each minute. So for 12W it will increment this value by 12,000 each minute. So it's mW/min. mWh is average milliwatts per hour... The Insight doesn't provide that.
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. At some point I hope to refactor some of the HA power/energy code - but this requires changing some of the base components properties - and any other components that override then. Until then I think you need to leave the official properties as they are - and add |
||
| """This is a total of average mW per minute.""" | ||
| if self.insight_params: | ||
| return self.insight_params['currentpower'] | ||
| try: | ||
| return self.insight_params['totalmw'] | ||
| except: | ||
| return None | ||
|
|
||
| @property | ||
| def today_power_mw(self): | ||
| """Today total power usage in mW.""" | ||
| def power_today_mw_min(self): | ||
| """This is the total consumption today in mW per minute.""" | ||
| if self.insight_params: | ||
| return self.insight_params['todaymw'] | ||
| try: | ||
| return self.insight_params['todaymw'] | ||
| except: | ||
| return None | ||
|
|
||
| @property | ||
| def detail_state(self): | ||
|
|
||
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.
Is this required?