8000 Return TP-Link attributes as `float` rather than `string` by spacegaier · Pull Request #48828 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Return TP-Link attributes as float rather than string #48828

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

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions homeassistant/components/tplink/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ def _update_emeter(self):
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 (
Expand All @@ -395,11 +395,11 @@ def _update_emeter(self):
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
Expand Down
20 changes: 10 additions & 10 deletions homeassistant/components/tplink/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,23 @@ def attempt_update(self, update_attempt):
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. 512B _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:
Expand Down
0