mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Daily consumption information for HS110 (#4206)
* Add daily consumption information for HS110 * Fixing code review * Fixing code review * Fixing code review
This commit is contained in:
parent
749fc583ea
commit
20af5cb5b4
@ -6,6 +6,8 @@ https://home-assistant.io/components/switch.tplink/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
|
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
|
||||||
@ -21,6 +23,7 @@ DEFAULT_NAME = 'TPLink Switch HS100'
|
|||||||
|
|
||||||
ATTR_CURRENT_CONSUMPTION = 'Current consumption'
|
ATTR_CURRENT_CONSUMPTION = 'Current consumption'
|
||||||
ATTR_TOTAL_CONSUMPTION = 'Total consumption'
|
ATTR_TOTAL_CONSUMPTION = 'Total consumption'
|
||||||
|
ATTR_DAILY_CONSUMPTION = 'Daily consumption'
|
||||||
ATTR_VOLTAGE = 'Voltage'
|
ATTR_VOLTAGE = 'Voltage'
|
||||||
ATTR_CURRENT = 'Current'
|
ATTR_CURRENT = 'Current'
|
||||||
|
|
||||||
@ -78,16 +81,24 @@ class SmartPlugSwitch(SwitchDevice):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the TP-Link switch's state."""
|
"""Update the TP-Link switch's state."""
|
||||||
self._state = self.smartplug.state
|
try:
|
||||||
|
self._state = self.smartplug.state
|
||||||
|
|
||||||
if self._emeter_present:
|
if self._emeter_present:
|
||||||
emeter_readings = self.smartplug.get_emeter_realtime()
|
emeter_readings = self.smartplug.get_emeter_realtime()
|
||||||
|
|
||||||
self._emeter_params[ATTR_CURRENT_CONSUMPTION] \
|
self._emeter_params[ATTR_CURRENT_CONSUMPTION] \
|
||||||
= "%.1f W" % emeter_readings["power"]
|
= "%.1f W" % emeter_readings["power"]
|
||||||
self._emeter_params[ATTR_TOTAL_CONSUMPTION] \
|
self._emeter_params[ATTR_TOTAL_CONSUMPTION] \
|
||||||
= "%.2f kW" % emeter_readings["total"]
|
= "%.2f kW" % emeter_readings["total"]
|
||||||
self._emeter_params[ATTR_VOLTAGE] \
|
self._emeter_params[ATTR_VOLTAGE] \
|
||||||
= "%.2f V" % emeter_readings["voltage"]
|
= "%.2f V" % emeter_readings["voltage"]
|
||||||
self._emeter_params[ATTR_CURRENT] \
|
self._emeter_params[ATTR_CURRENT] \
|
||||||
= "%.1f A" % emeter_readings["current"]
|
= "%.1f A" % emeter_readings["current"]
|
||||||
|
|
||||||
|
emeter_statics = self.smartplug.get_emeter_daily()
|
||||||
|
self._emeter_params[ATTR_DAILY_CONSUMPTION] \
|
||||||
|
= "%.2f kW" % emeter_statics[int(time.strftime("%e"))]
|
||||||
|
|
||||||
|
except OSError:
|
||||||
|
_LOGGER.warning('Could not update status for %s', self.name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user