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

Remove lock variables from Cover device state attributes #108

Merged
merged 2 commits into from
Jul 6, 2020
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
3 changes: 0 additions & 3 deletions custom_components/tahoma/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@
# TaHoma Attributes
ATTR_MEM_POS = "memorized_position"
ATTR_RSSI_LEVEL = "rssi_level"
ATTR_LOCK_START_TS = "lock_start_ts"
ATTR_LOCK_END_TS = "lock_end_ts"
ATTR_LOCK_LEVEL = "lock_level"
ATTR_LOCK_ORIG = "lock_originator"

# TaHoma internal device states
Expand Down
52 changes: 5 additions & 47 deletions custom_components/tahoma/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@
SUPPORT_STOP_TILT,
CoverEntity,
)
from homeassistant.util.dt import utcnow

from .const import (
ATTR_LOCK_END_TS,
ATTR_LOCK_LEVEL,
ATTR_LOCK_ORIG,
ATTR_LOCK_START_TS,
ATTR_MEM_POS,
COMMAND_SET_CLOSURE,
COMMAND_SET_ORIENTATION,
Expand All @@ -41,7 +37,6 @@
CORE_SLATS_ORIENTATION_STATE,
CORE_TARGET_CLOSURE_STATE,
DOMAIN,
IO_PRIORITY_LOCK_LEVEL_STATE,
IO_PRIORITY_LOCK_ORIGINATOR_STATE,
TAHOMA_COVER_DEVICE_CLASSES,
TAHOMA_TYPES,
Expand Down Expand Up @@ -77,15 +72,7 @@ def __init__(self, tahoma_device, controller):
self._tilt_position = None
self._position = None

self._icon = None
self._lock_timer = 0 # Can be 0 and bigger
self._lock_start_ts = None
self._lock_end_ts = None

# Can be 'comfortLevel1', 'comfortLevel2', 'comfortLevel3',
# 'comfortLevel4', 'environmentProtection', 'humanProtection',
# 'userLevel1', 'userLevel2'
self._lock_level = None

# Can be 'LSC', 'SAAC', 'SFC', 'UPS', 'externalGateway', 'localUser',
# 'myself', 'rain', 'security', 'temperature', 'timer', 'user', 'wind'
Expand Down Expand Up @@ -144,29 +131,7 @@ def update_tilt_position(self):

def update_lock(self):
states = self.tahoma_device.active_states
if CORE_PRIORITY_LOCK_TIMER_STATE in states:
old_lock_timer = self._lock_timer
self._lock_timer = states[CORE_PRIORITY_LOCK_TIMER_STATE]

# Derive timestamps from _lock_timer, only if not already set or something has changed
if self._lock_timer > 0:
_LOGGER.debug("Update %s, lock_timer: %d", self._name, self._lock_timer)
if self._lock_start_ts is None:
self._lock_start_ts = utcnow()
if self._lock_end_ts is None or old_lock_timer != self._lock_timer:
self._lock_end_ts = utcnow() + timedelta(seconds=self._lock_timer)
else:
self._lock_start_ts = None
self._lock_end_ts = None
else:
self._lock_timer = 0
self._lock_start_ts = None
self._lock_end_ts = None

# Set Lock Level
self._lock_level = states.get(IO_PRIORITY_LOCK_LEVEL_STATE)

# Set Lock Originator
self._lock_timer = states.get(CORE_PRIORITY_LOCK_TIMER_STATE, 0)
self._lock_originator = states.get(IO_PRIORITY_LOCK_ORIGINATOR_STATE)

@property
Expand Down Expand Up @@ -255,12 +220,6 @@ def device_state_attributes(self):
attr[ATTR_MEM_POS] = self.tahoma_device.active_states[
CORE_MEMORIZED_1_POSITION_STATE
]
if self._lock_start_ts is not None:
attr[ATTR_LOCK_START_TS] = self._lock_start_ts.isoformat()
if self._lock_end_ts is not None:
attr[ATTR_LOCK_END_TS] = self._lock_end_ts.isoformat()
if self._lock_level is not None:
attr[ATTR_LOCK_LEVEL] = self._lock_level
if self._lock_originator is not None:
attr[ATTR_LOCK_ORIG] = self._lock_originator

Expand All @@ -269,13 +228,12 @@ def device_state_attributes(self):
@property
def icon(self):
"""Return the icon to use in the frontend, if any."""
icon = None
if self._lock_timer > 0:
icon = "mdi:lock-alert"
if self._lock_originator == "wind":
return "mdi:weather-windy"
else:
return "mdi:lock-alert"

return self._icon
icon = "mdi:weather-windy"
return icon
tetienne marked this conversation as resolved.
Show resolved Hide resolved

def open_cover(self, **kwargs):
"""Open the cover."""
Expand Down