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

Add active_states to device_state_attributes #89

Merged
merged 2 commits into from
Jun 25, 2020
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
25 changes: 20 additions & 5 deletions custom_components/tahoma/tahoma_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,27 @@ def device_state_attributes(self):
CORE_RSSI_LEVEL_STATE
]

# TODO Parse 'lowBattery' for low battery warning. 'dead' for not available.
# "dead", "lowBattery", "maintenanceRequired", "noDefect"
if "core:BatteryState" in self.tahoma_device.active_states:
battery_state = self.tahoma_device.active_states["core:BatteryState"]

if battery_state == "full":
battery_state = 100
elif battery_state == "normal":
battery_state = 75
elif battery_state == "low":
battery_state = 25
elif battery_state == "verylow":
battery_state = 10

attr[ATTR_BATTERY_LEVEL] = battery_state

if CORE_SENSOR_DEFECT_STATE in self.tahoma_device.active_states:
attr[ATTR_BATTERY_LEVEL] = self.tahoma_device.active_states[
CORE_SENSOR_DEFECT_STATE
]
if self.tahoma_device.active_states.get(CORE_SENSOR_DEFECT_STATE) == "dead":
attr[ATTR_BATTERY_LEVEL] = 0

for state_name, value in self.tahoma_device.active_states.items():
if "State" in state_name:
attr[state_name] = value

return attr

Expand Down