1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00

Return TP-Link sensor & light attributes as float rather than string (#48828)

This commit is contained in:
Philip Allgaier 2021-04-08 16:51:59 +02:00 committed by GitHub
parent 91837f08ce
commit f1c4072d3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 16 deletions

View File

@ -382,8 +382,8 @@ class TPLinkSmartBulb(LightEntity):
or self._last_current_power_update + CURRENT_POWER_UPDATE_INTERVAL < now
):
self._last_current_power_update = now
self._emeter_params[ATTR_CURRENT_POWER_W] = "{:.1f}".format(
self.smartbulb.current_consumption()
self._emeter_params[ATTR_CURRENT_POWER_W] = round(
float(self.smartbulb.current_consumption()), 1
)
if (
@ -395,11 +395,11 @@ class TPLinkSmartBulb(LightEntity):
daily_statistics = self.smartbulb.get_emeter_daily()
monthly_statistics = self.smartbulb.get_emeter_monthly()
try:
self._emeter_params[ATTR_DAILY_ENERGY_KWH] = "{:.3f}".format(
daily_statistics[int(time.strftime("%d"))]
self._emeter_params[ATTR_DAILY_ENERGY_KWH] = round(
float(daily_statistics[int(time.strftime("%d"))]), 3
)
self._emeter_params[ATTR_MONTHLY_ENERGY_KWH] = "{:.3f}".format(
monthly_statistics[int(time.strftime("%m"))]
self._emeter_params[ATTR_MONTHLY_ENERGY_KWH] = round(
float(monthly_statistics[int(time.strftime("%m"))]), 3
)
except KeyError:
# device returned no daily/monthly history

View File

@ -138,23 +138,23 @@ class SmartPlugSwitch(SwitchEntity):
if self.smartplug.has_emeter:
emeter_readings = self.smartplug.get_emeter_realtime()
self._emeter_params[ATTR_CURRENT_POWER_W] = "{:.2f}".format(
emeter_readings["power"]
self._emeter_params[ATTR_CURRENT_POWER_W] = round(
float(emeter_readings["power"]), 2
)
self._emeter_params[ATTR_TOTAL_ENERGY_KWH] = "{:.3f}".format(
emeter_readings["total"]
self._emeter_params[ATTR_TOTAL_ENERGY_KWH] = round(
float(emeter_readings["total"]), 3
)
self._emeter_params[ATTR_VOLTAGE] = "{:.1f}".format(
emeter_readings["voltage"]
self._emeter_params[ATTR_VOLTAGE] = round(
float(emeter_readings["voltage"]), 1
)
self._emeter_params[ATTR_CURRENT_A] = "{:.2f}".format(
emeter_readings["current"]
self._emeter_params[ATTR_CURRENT_A] = round(
float(emeter_readings["current"]), 2
)
emeter_statics = self.smartplug.get_emeter_daily()
with suppress(KeyError): # Device returned no daily history
self._emeter_params[ATTR_TODAY_ENERGY_KWH] = "{:.3f}".format(
emeter_statics[int(time.strftime("%e"))]
self._emeter_params[ATTR_TODAY_ENERGY_KWH] = round(
float(emeter_statics[int(time.strftime("%e"))]), 3
)
return True
except (SmartDeviceException, OSError) as ex: