8000 Use default None for voltage property of FritzDevice in Fritz!Smarthome by mib1185 · Pull Request #73141 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use default None for voltage property of FritzDevice in Fritz!Smarthome #73141

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
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
6 changes: 4 additions & 2 deletions homeassistant/components/fritzbox/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ class FritzSensorEntityDescription(
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
suitable=lambda device: device.has_powermeter, # type: ignore[no-any-return]
native_value=lambda device: device.voltage / 1000 if device.voltage else 0.0,
native_value=lambda device: device.voltage / 1000
if getattr(device, "voltage", None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you check explicitely for None to guard for device.voltage being 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is a value, it must be >0, since the smart plug needs some voltage to work 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding style, I think we try to avoid multi-line lambdas but if this is a hotfix maybe it doesn't apply here

else 0.0,
),
FritzSensorEntityDescription(
key="electric_current",
Expand All @@ -106,7 +108,7 @@ class FritzSensorEntityDescription(
state_class=SensorStateClass.MEASUREMENT,
suitable=lambda device: device.has_powermeter, # type: ignore[no-any-return]
native_value=lambda device: device.power / device.voltage
if device.power and device.voltage
if device.power and getattr(device, "voltage", None)
else 0.0,
),
FritzSensorEntityDescription(
Expand Down
0