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 totalconnect zones as binary sensors #28712

Merged
merged 60 commits into from
Feb 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
54dbdd6
Merge pull request #1 from home-assistant/dev
austinmroczek Apr 14, 2019
90483d2
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
austinmroczek Apr 18, 2019
51aa773
Bump skybellpy to 0.4.0
austinmroczek Apr 18, 2019
e18b4d2
Bump skybellpy to 0.4.0 in requirements_all.txt
austinmroczek Apr 22, 2019
d74156a
Added extra states for STATE_ALARM_TRIGGERED to allow users to know if
austinmroczek Apr 26, 2019
ad1cdb3
Merge branch 'dev' of https://github.com/austinmroczek/home-assistant…
austinmroczek Apr 26, 2019
5c5c052
Merge pull request #2 from home-assistant/dev
austinmroczek Apr 26, 2019
abcc85a
Fix const import
austinmroczek Apr 28, 2019
d303091
Fix const import
austinmroczek Apr 28, 2019
73f38eb
Fix const imports
austinmroczek Apr 28, 2019
5bec7e4
Bump total-connect-client to 0.26.
austinmroczek May 5, 2019
4862ff5
Catch details of alarm trigger in state attributes.
austinmroczek May 25, 2019
5068345
Merge branch 'dev' of
austinmroczek May 25, 2019
e7a13d4
Change state_attributes() to device_state_attributes()
austinmroczek May 30, 2019
53f20fb
Merge remote-tracking branch 'upstream/dev' into dev
austinmroczek Jun 7, 2019
4bee662
Merge branch 'dev' of https://github.com/austinmroczek/home-assistant…
austinmroczek Jun 7, 2019
6a50e80
Move totalconnect component toward being a multi-platform integration…
austinmroczek Jun 8, 2019
37c34cf
Merge pull request #4 from home-assistant/dev
austinmroczek Jun 29, 2019
ad4c4c9
add missing total-connect alarm state mappings
austinmroczek Jun 29, 2019
e589317
Made recommended changes of MartinHjelmare at
austinmroczek Jun 30, 2019
aa22440
Update __init__.py
austinmroczek Jul 2, 2019
5cbfc98
Updates per MartinHjelmare comments
austinmroczek Jul 13, 2019
eb440cc
flake8/pydocstyle fixes
austinmroczek Jul 13, 2019
69425d7
Merge branch 'dev' of https://github.com/austinmroczek/home-assistant…
austinmroczek Jul 13, 2019
117ed1b
removed . at end of log message
austinmroczek Jul 13, 2019
14d3e2e
added blank line between logging and voluptuous
austinmroczek Jul 13, 2019
cd2b563
more fixes
austinmroczek Jul 14, 2019
2295b7c
Merge remote-tracking branch 'upstream/dev' into dev
austinmroczek Nov 10, 2019
db6336b
Adding totalconnect zones as HA binary_sensors
austinmroczek Nov 10, 2019
e9a0e69
fix manifest.json
austinmroczek Nov 10, 2019
1bc164d
flake8/pydocstyle fixes. Added codeowner.
austinmroczek Nov 12, 2019
932e5b0
Update formatting per @springstan guidance.
austinmroczek Nov 16, 2019
bf7be02
Fixed pylint
austinmroczek Nov 16, 2019
f855154
Merge remote-tracking branch 'upstream/dev' into dev
austinmroczek Dec 15, 2019
fcadf80
Add zone ID to log message for easier troubleshooting
austinmroczek Dec 15, 2019
a68576e
Account for bypassed zones in update()
austinmroczek Dec 19, 2019
a15b4de
More status handling fixes.
austinmroczek Dec 21, 2019
ea1510f
Fixed flake8 error
austinmroczek Dec 21, 2019
7f7ec1c
Another attempt at black/isort fixes.
austinmroczek Dec 21, 2019
4de1bcf
Bump total-connect-client to 0.50. Simplify code using new functions in
austinmroczek Jan 14, 2020
b66ba1f
Fix manifest file
austinmroczek Jan 14, 2020
4027382
Another manifest fix
austinmroczek Jan 14, 2020
656e88d
one more manifest fix
austinmroczek Jan 14, 2020
eca1045
more manifest changes.
austinmroczek Jan 14, 2020
750fc0b
sync up
austinmroczek Jan 15, 2020
fd927a3
Merge remote-tracking branch 'upstream/dev' into dev
austinmroczek Jan 15, 2020
10f1642
Merge branch 'dev' of https://github.com/austinmroczek/home-assistant…
austinmroczek Jan 15, 2020
25f530b
fix indent
austinmroczek Jan 17, 2020
d9700f8
one more pylint fix
austinmroczek Jan 17, 2020
81f4cef
Hopefully the last pylint fix
austinmroczek Jan 17, 2020
6f0e779
make variable names understandable
austinmroczek Jan 18, 2020
c654941
create and fill dict in one step
austinmroczek Jan 18, 2020
1c32671
Fix name and attributes
austinmroczek Jan 18, 2020
35d3085
rename to logical variable in alarm_control_panel
austinmroczek Jan 18, 2020
c9b208d
Remove location_name from alarm_control_panel attributes since it is
austinmroczek Jan 19, 2020
10b555e
Multiple fixes to improve code per @springstan suggestions
austinmroczek Jan 19, 2020
19b0c63
Update homeassistant/components/totalconnect/binary_sensor.py
austinmroczek Jan 22, 2020
471b01a
Multiple changes per @MartinHjelmare review
austinmroczek Jan 31, 2020
ef06453
simplify alarm adding
austinmroczek Jan 31, 2020
0c1234e
Fix binary_sensor.py is_on
austinmroczek Jan 31, 2020
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
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ homeassistant/components/time_date/* @fabaff
homeassistant/components/tmb/* @alemuro
homeassistant/components/todoist/* @boralyl
homeassistant/components/toon/* @frenck
homeassistant/components/totalconnect/* @austinmroczek
homeassistant/components/tplink/* @rytilahti
homeassistant/components/traccar/* @ludeeus
homeassistant/components/tradfri/* @ggravlingen
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/totalconnect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
extra=vol.ALLOW_EXTRA,
)

TOTALCONNECT_PLATFORMS = ["alarm_control_panel"]
TOTALCONNECT_PLATFORMS = ["alarm_control_panel", "binary_sensor"]


def setup(hass, config):
Expand Down
51 changes: 25 additions & 26 deletions homeassistant/components/totalconnect/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):

client = hass.data[TOTALCONNECT_DOMAIN].client

for location in client.locations:
location_id = location.get("LocationID")
name = location.get("LocationName")
alarms.append(TotalConnectAlarm(name, location_id, client))
for location_id, location in client.locations.items():
location_name = location.location_name
alarms.append(TotalConnectAlarm(location_name, location_id, client))
add_entities(alarms)


Expand Down Expand Up @@ -72,35 +71,35 @@ def device_state_attributes(self):

def update(self):
"""Return the state of the device."""
status = self._client.get_armed_status(self._name)
status = self._client.get_armed_status(self._location_id)
attr = {
"location_name": self._name,
austinmroczek marked this conversation as resolved.
Show resolved Hide resolved
"location_id": self._location_id,
"ac_loss": self._client.ac_loss,
"low_battery": self._client.low_battery,
"ac_loss": self._client.locations[self._location_id].ac_loss,
"low_battery": self._client.locations[self._location_id].low_battery,
"cover_tampered": self._client.locations[
self._location_id
].is_cover_tampered,
"triggered_source": None,
"triggered_zone": None,
}

if status == self._client.DISARMED:
if status in (self._client.DISARMED, self._client.DISARMED_BYPASS):
state = STATE_ALARM_DISARMED
elif status == self._client.DISARMED_BYPASS:
state = STATE_ALARM_DISARMED
elif status == self._client.ARMED_STAY:
state = STATE_ALARM_ARMED_HOME
elif status == self._client.ARMED_STAY_INSTANT:
state = STATE_ALARM_ARMED_HOME
elif status == self._client.ARMED_STAY_INSTANT_BYPASS:
elif status in (
self._client.ARMED_STAY,
self._client.ARMED_STAY_INSTANT,
self._client.ARMED_STAY_INSTANT_BYPASS,
):
state = STATE_ALARM_ARMED_HOME
elif status == self._client.ARMED_STAY_NIGHT:
state = STATE_ALARM_ARMED_NIGHT
elif status == self._client.ARMED_AWAY:
state = STATE_ALARM_ARMED_AWAY
elif status == self._client.ARMED_AWAY_BYPASS:
state = STATE_ALARM_ARMED_AWAY
elif status == self._client.ARMED_AWAY_INSTANT:
state = STATE_ALARM_ARMED_AWAY
elif status == self._client.ARMED_AWAY_INSTANT_BYPASS:
elif status in (
self._client.ARMED_AWAY,
self._client.ARMED_AWAY_BYPASS,
self._client.ARMED_AWAY_INSTANT,
self._client.ARMED_AWAY_INSTANT_BYPASS,
):
state = STATE_ALARM_ARMED_AWAY
elif status == self._client.ARMED_CUSTOM_BYPASS:
state = STATE_ALARM_ARMED_CUSTOM_BYPASS
Expand Down Expand Up @@ -128,16 +127,16 @@ def update(self):

def alarm_disarm(self, code=None):
"""Send disarm command."""
self._client.disarm(self._name)
self._client.disarm(self._location_id)

def alarm_arm_home(self, code=None):
"""Send arm home command."""
self._client.arm_stay(self._name)
self._client.arm_stay(self._location_id)

def alarm_arm_away(self, code=None):
"""Send arm away command."""
self._client.arm_away(self._name)
self._client.arm_away(self._location_id)

def alarm_arm_night(self, code=None):
"""Send arm night command."""
self._client.arm_stay_night(self._name)
self._client.arm_stay_night(self._location_id)
90 changes: 90 additions & 0 deletions homeassistant/components/totalconnect/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""Interfaces with TotalConnect sensors."""
import logging

from homeassistant.components.binary_sensor import (
DEVICE_CLASS_DOOR,
DEVICE_CLASS_GAS,
DEVICE_CLASS_SMOKE,
BinarySensorDevice,
)

from . import DOMAIN as TOTALCONNECT_DOMAIN

_LOGGER = logging.getLogger(__name__)


def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up a sensor for a TotalConnect device."""
if discovery_info is None:
return

sensors = []

client_locations = hass.data[TOTALCONNECT_DOMAIN].client.locations

for location_id, location in client_locations.items():
for zone_id, zone in location.zones.items():
sensors.append(TotalConnectBinarySensor(zone_id, location_id, zone))
add_entities(sensors, True)


class TotalConnectBinarySensor(BinarySensorDevice):
"""Represent an TotalConnect zone."""

def __init__(self, zone_id, location_id, zone):
"""Initialize the TotalConnect status."""
self._zone_id = zone_id
self._location_id = location_id
self._zone = zone
self._name = self._zone.description
austinmroczek marked this conversation as resolved.
Show resolved Hide resolved
self._unique_id = f"{location_id} {zone_id}"
self._is_on = None
self._is_tampered = None
self._is_low_battery = None

@property
def unique_id(self):
"""Return the unique id."""
return self._unique_id

@property
def name(self):
"""Return the name of the device."""
return self._name

def update(self):
"""Return the state of the device."""
self._is_tampered = self._zone.is_tampered()
self._is_low_battery = self._zone.is_low_battery()

if self._zone.is_faulted() or self._zone.is_triggered():
self._is_on = True
else:
self._is_on = False

@property
def is_on(self):
"""Return true if the binary sensor is on."""
return self._is_on

@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
if self._zone.is_type_security():
austinmroczek marked this conversation as resolved.
Show resolved Hide resolved
return DEVICE_CLASS_DOOR
if self._zone.is_type_fire():
return DEVICE_CLASS_SMOKE
if self._zone.is_type_carbon_monoxide():
return DEVICE_CLASS_GAS
return None
springstan marked this conversation as resolved.
Show resolved Hide resolved

@property
def device_state_attributes(self):
"""Return the state attributes."""
attributes = {
"zone_id": self._zone_id,
"location_id": self._location_id,
"low_battery": self._is_low_battery,
"tampered": self._is_tampered,
}
return attributes
4 changes: 2 additions & 2 deletions homeassistant/components/totalconnect/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "totalconnect",
"name": "Honeywell Total Connect Alarm",
"documentation": "https://www.home-assistant.io/integrations/totalconnect",
"requirements": ["total_connect_client==0.28"],
"requirements": ["total_connect_client==0.50"],
"dependencies": [],
"codeowners": []
"codeowners": ["@austinmroczek"]
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1975,7 +1975,7 @@ todoist-python==8.0.0
toonapilib==3.2.4

# homeassistant.components.totalconnect
total_connect_client==0.28
total_connect_client==0.50

# homeassistant.components.tplink_lte
tp-connected==0.0.4
Expand Down