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 Vera last user and low battery attributes #27043

Merged
merged 9 commits into from
Oct 2, 2019
32 changes: 32 additions & 0 deletions homeassistant/components/vera/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

_LOGGER = logging.getLogger(__name__)

ATTR_LAST_USER_NAME = "changed_by_name"
ATTR_LOW_BATTERY = "low_battery"


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Find and return Vera locks."""
Expand Down Expand Up @@ -44,6 +47,35 @@ def is_locked(self):
"""Return true if device is on."""
return self._state == STATE_LOCKED

@property
def device_state_attributes(self):
"""Who unlocked the lock and did a low battery alert fire.

Reports on the previous poll cycle.
changed_by_name is a string like 'Bob'.
low_battery is 1 if an alert fired, 0 otherwise.
"""
data = super().device_state_attributes

last_user = self.vera_device.get_last_user_alert()
if last_user is not None:
data[ATTR_LAST_USER_NAME] = last_user[1]

data[ATTR_LOW_BATTERY] = self.vera_device.get_low_battery_alert()
return data

@property
def changed_by(self):
"""Who unlocked the lock.

Reports on the previous poll cycle.
changed_by is an integer user ID.
"""
last_user = self.vera_device.get_last_user_alert()
if last_user is not None:
return last_user[0]
return None

def update(self):
"""Update state by the Vera device callback."""
self._state = (
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/vera/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Vera",
"documentation": "https://www.home-assistant.io/components/vera",
"requirements": [
"pyvera==0.3.4"
"pyvera==0.3.6"
],
"dependencies": [],
"codeowners": []
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ pyuptimerobot==0.0.5
# pyuserinput==0.1.11

# homeassistant.components.vera
pyvera==0.3.4
pyvera==0.3.6
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved

# homeassistant.components.vesync
pyvesync==1.1.0
Expand Down