-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add Tahoma lock support #31311
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 Tahoma lock support #31311
Changes from 5 commits
9c0ec2b
8b54501
989d500
488c7f3
62489b4
1fb9fd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| """Support for Tahoma lock.""" | ||
| from datetime import timedelta | ||
| import logging | ||
|
|
||
| from homeassistant.components.lock import LockDevice | ||
| from homeassistant.const import ( | ||
| ATTR_BATTERY_LEVEL, | ||
| ATTR_NAME, | ||
| STATE_LOCKED, | ||
| STATE_UNLOCKED, | ||
| ) | ||
|
|
||
| from . import DOMAIN as TAHOMA_DOMAIN, TahomaDevice | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| SCAN_INTERVAL = timedelta(seconds=120) | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_entities, discovery_info=None): | ||
| """Set up the Tahoma lock.""" | ||
| controller = hass.data[TAHOMA_DOMAIN]["controller"] | ||
| devices = [] | ||
| for device in hass.data[TAHOMA_DOMAIN]["devices"]["lock"]: | ||
| devices.append(TahomaLock(device, controller)) | ||
| add_entities(devices, True) | ||
|
|
||
|
|
||
| class TahomaLock(TahomaDevice, LockDevice): | ||
| """Representation a Tahoma lock.""" | ||
|
|
||
| def __init__(self, tahoma_device, controller): | ||
| """Initialize the device.""" | ||
| super().__init__(tahoma_device, controller) | ||
| self._lock_status = None | ||
| self._available = False | ||
|
springstan marked this conversation as resolved.
|
||
| self._battery_level = None | ||
| self._name = None | ||
|
vlebourl marked this conversation as resolved.
|
||
|
|
||
| def update(self): | ||
| """Update method.""" | ||
| self.controller.get_states([self.tahoma_device]) | ||
| self._battery_level = self.tahoma_device.active_states["core:BatteryState"] | ||
| self._name = self.tahoma_device.active_states["core:NameState"] | ||
| if self._battery_level == "low": | ||
| _LOGGER.warning("Lock %s has low battery", self._name) | ||
| if self._battery_level == "verylow": | ||
| _LOGGER.error("Lock %s has very low battery", self._name) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't log errors if the application is functioning normally. The low battery level is just a state at the device. It's not a problem with Home Assistant. The user can make an automation that triggers an alert if the battery level attribute reaches a certain value. |
||
| if ( | ||
| self.tahoma_device.active_states.get("core:LockedUnlockedState") | ||
| == STATE_LOCKED | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't use the home assistant state constant to compare with the tahoma state API. These are two different APIs and either may change independently of the other. Please define a separate string constant for the tahoma API to use here. |
||
| ): | ||
| self._lock_status = STATE_LOCKED | ||
| else: | ||
| self._lock_status = STATE_UNLOCKED | ||
| self._available = ( | ||
| self.tahoma_device.active_states.get("core:AvailabilityState") | ||
| == "available" | ||
| ) | ||
|
|
||
| def unlock(self, **kwargs): | ||
| """Unlock method.""" | ||
| _LOGGER.debug("Unlocking %s", self._name) | ||
| self.apply_action("unlock") | ||
|
|
||
| def lock(self, **kwargs): | ||
| """Lock method.""" | ||
| _LOGGER.debug("Locking %s", self._name) | ||
| self.apply_action("lock") | ||
|
|
||
| @property | ||
| def is_locked(self): | ||
| """Return true if the lock is locked.""" | ||
| return self._lock_status == STATE_LOCKED | ||
|
|
||
| @property | ||
| def device_state_attributes(self): | ||
| """Return the device state attributes.""" | ||
| attr = { | ||
| ATTR_BATTERY_LEVEL: self.tahoma_device.active_states["core:BatteryState"], | ||
|
springstan marked this conversation as resolved.
Outdated
|
||
| "availability": self.tahoma_device.active_states["core:AvailabilityState"], | ||
| ATTR_NAME: self.tahoma_device.active_states["core:NameState"], | ||
|
springstan marked this conversation as resolved.
Outdated
|
||
| } | ||
| super_attr = super().device_state_attributes | ||
| if super_attr is not None: | ||
| attr.update(super_attr) | ||
| return attr | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a guard clause here that checks if discovery_info is None and return if so.