Skip to content
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

Fix unknown data in vultr #85627

Merged
merged 2 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions homeassistant/components/vultr/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@ def name(self):
@property
def native_value(self):
"""Return the value of this given sensor type."""
value = self.data.get(self.entity_description.key)
if value == "not a number":
frenck marked this conversation as resolved.
Show resolved Hide resolved
return None
try:
return round(float(self.data.get(self.entity_description.key)), 2)
return round(float(value), 2)
except (TypeError, ValueError):
return self.data.get(self.entity_description.key)
return value

def update(self) -> None:
"""Update state of sensor."""
Expand Down
2 changes: 1 addition & 1 deletion tests/components/vultr/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def add_entities(devices, action):

elif device.subscription == "123456": # Custom name with 1 {}
assert device.name == "Server Pending Charges"
assert device.state == "not a number"
assert device.state is None
tested += 1

elif device.subscription == "555555": # No {} in name
Expand Down