mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Be tolerant of Wemo insight_param keys that might not exist (#55232)
This commit is contained in:
parent
6d4a47a53d
commit
56246056ce
@ -78,7 +78,9 @@ class InsightCurrentPower(InsightSensor):
|
|||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType:
|
||||||
"""Return the current power consumption."""
|
"""Return the current power consumption."""
|
||||||
return (
|
return (
|
||||||
convert(self.wemo.insight_params[self.entity_description.key], float, 0.0)
|
convert(
|
||||||
|
self.wemo.insight_params.get(self.entity_description.key), float, 0.0
|
||||||
|
)
|
||||||
/ 1000.0
|
/ 1000.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -98,6 +100,6 @@ class InsightTodayEnergy(InsightSensor):
|
|||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType:
|
||||||
"""Return the current energy use today."""
|
"""Return the current energy use today."""
|
||||||
miliwatts = convert(
|
miliwatts = convert(
|
||||||
self.wemo.insight_params[self.entity_description.key], float, 0.0
|
self.wemo.insight_params.get(self.entity_description.key), float, 0.0
|
||||||
)
|
)
|
||||||
return round(miliwatts / (1000.0 * 1000.0 * 60), 2)
|
return round(miliwatts / (1000.0 * 1000.0 * 60), 2)
|
||||||
|
@ -76,16 +76,17 @@ class WemoSwitch(WemoEntity, SwitchEntity):
|
|||||||
|
|
||||||
if isinstance(self.wemo, Insight):
|
if isinstance(self.wemo, Insight):
|
||||||
attr["on_latest_time"] = WemoSwitch.as_uptime(
|
attr["on_latest_time"] = WemoSwitch.as_uptime(
|
||||||
self.wemo.insight_params["onfor"]
|
self.wemo.insight_params.get("onfor", 0)
|
||||||
)
|
)
|
||||||
attr["on_today_time"] = WemoSwitch.as_uptime(
|
attr["on_today_time"] = WemoSwitch.as_uptime(
|
||||||
self.wemo.insight_params["ontoday"]
|
self.wemo.insight_params.get("ontoday", 0)
|
||||||
)
|
)
|
||||||
attr["on_total_time"] = WemoSwitch.as_uptime(
|
attr["on_total_time"] = WemoSwitch.as_uptime(
|
||||||
self.wemo.insight_params["ontotal"]
|
self.wemo.insight_params.get("ontotal", 0)
|
||||||
)
|
)
|
||||||
attr["power_threshold_w"] = (
|
attr["power_threshold_w"] = (
|
||||||
convert(self.wemo.insight_params["powerthreshold"], float, 0.0) / 1000.0
|
convert(self.wemo.insight_params.get("powerthreshold"), float, 0.0)
|
||||||
|
/ 1000.0
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(self.wemo, CoffeeMaker):
|
if isinstance(self.wemo, CoffeeMaker):
|
||||||
@ -106,14 +107,15 @@ class WemoSwitch(WemoEntity, SwitchEntity):
|
|||||||
"""Return the current power usage in W."""
|
"""Return the current power usage in W."""
|
||||||
if isinstance(self.wemo, Insight):
|
if isinstance(self.wemo, Insight):
|
||||||
return (
|
return (
|
||||||
convert(self.wemo.insight_params["currentpower"], float, 0.0) / 1000.0
|
convert(self.wemo.insight_params.get("currentpower"), float, 0.0)
|
||||||
|
/ 1000.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def today_energy_kwh(self):
|
def today_energy_kwh(self):
|
||||||
"""Return the today total energy usage in kWh."""
|
"""Return the today total energy usage in kWh."""
|
||||||
if isinstance(self.wemo, Insight):
|
if isinstance(self.wemo, Insight):
|
||||||
miliwatts = convert(self.wemo.insight_params["todaymw"], float, 0.0)
|
miliwatts = convert(self.wemo.insight_params.get("todaymw"), float, 0.0)
|
||||||
return round(miliwatts / (1000.0 * 1000.0 * 60), 2)
|
return round(miliwatts / (1000.0 * 1000.0 * 60), 2)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -122,7 +124,7 @@ class WemoSwitch(WemoEntity, SwitchEntity):
|
|||||||
if isinstance(self.wemo, CoffeeMaker):
|
if isinstance(self.wemo, CoffeeMaker):
|
||||||
return self.wemo.mode_string
|
return self.wemo.mode_string
|
||||||
if isinstance(self.wemo, Insight):
|
if isinstance(self.wemo, Insight):
|
||||||
standby_state = int(self.wemo.insight_params["state"])
|
standby_state = int(self.wemo.insight_params.get("state", 0))
|
||||||
if standby_state == WEMO_ON:
|
if standby_state == WEMO_ON:
|
||||||
return STATE_ON
|
return STATE_ON
|
||||||
if standby_state == WEMO_OFF:
|
if standby_state == WEMO_OFF:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user