mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Move totalconnect from platform to component config (#24427)
* Move totalconnect component toward being a multi-platform integration. Bump total_connect_client to 0.28. * add missing total-connect alarm state mappings * Made recommended changes of MartinHjelmare at https://github.com/home-assistant/home-assistant/pull/24427 * Update __init__.py * Updates per MartinHjelmare comments * flake8/pydocstyle fixes * removed . at end of log message * added blank line between logging and voluptuous * more fixes
This commit is contained in:
parent
b77d060304
commit
369e6a3905
@ -633,7 +633,7 @@ omit =
|
|||||||
homeassistant/components/tomato/device_tracker.py
|
homeassistant/components/tomato/device_tracker.py
|
||||||
homeassistant/components/toon/*
|
homeassistant/components/toon/*
|
||||||
homeassistant/components/torque/sensor.py
|
homeassistant/components/torque/sensor.py
|
||||||
homeassistant/components/totalconnect/alarm_control_panel.py
|
homeassistant/components/totalconnect/*
|
||||||
homeassistant/components/touchline/climate.py
|
homeassistant/components/touchline/climate.py
|
||||||
homeassistant/components/tplink/device_tracker.py
|
homeassistant/components/tplink/device_tracker.py
|
||||||
homeassistant/components/tplink/light.py
|
homeassistant/components/tplink/light.py
|
||||||
|
@ -1 +1,54 @@
|
|||||||
"""The totalconnect component."""
|
"""The totalconnect component."""
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
from total_connect_client import TotalConnectClient
|
||||||
|
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers import discovery
|
||||||
|
from homeassistant.const import (CONF_PASSWORD, CONF_USERNAME)
|
||||||
|
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DOMAIN = 'totalconnect'
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
|
DOMAIN: vol.Schema({
|
||||||
|
vol.Required(CONF_USERNAME): cv.string,
|
||||||
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
|
}),
|
||||||
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
TOTALCONNECT_PLATFORMS = ['alarm_control_panel']
|
||||||
|
|
||||||
|
|
||||||
|
def setup(hass, config):
|
||||||
|
"""Set up TotalConnect component."""
|
||||||
|
conf = config[DOMAIN]
|
||||||
|
|
||||||
|
username = conf[CONF_USERNAME]
|
||||||
|
password = conf[CONF_PASSWORD]
|
||||||
|
|
||||||
|
client = TotalConnectClient.TotalConnectClient(username, password)
|
||||||
|
|
||||||
|
if client.token is False:
|
||||||
|
_LOGGER.error("TotalConnect authentication failed")
|
||||||
|
return False
|
||||||
|
|
||||||
|
hass.data[DOMAIN] = TotalConnectSystem(username, password, client)
|
||||||
|
|
||||||
|
for platform in TOTALCONNECT_PLATFORMS:
|
||||||
|
discovery.load_platform(hass, platform, DOMAIN, {}, config)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class TotalConnectSystem:
|
||||||
|
"""TotalConnect System class."""
|
||||||
|
|
||||||
|
def __init__(self, username, password, client):
|
||||||
|
"""Initialize the TotalConnect system."""
|
||||||
|
self._username = username
|
||||||
|
self._password = password
|
||||||
|
self.client = client
|
||||||
|
@ -1,53 +1,43 @@
|
|||||||
"""Interfaces with TotalConnect alarm control panels."""
|
"""Interfaces with TotalConnect alarm control panels."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
import homeassistant.components.alarm_control_panel as alarm
|
import homeassistant.components.alarm_control_panel as alarm
|
||||||
from homeassistant.components.alarm_control_panel import PLATFORM_SCHEMA
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_PASSWORD, CONF_USERNAME, STATE_ALARM_ARMED_AWAY,
|
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_NIGHT,
|
||||||
STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_NIGHT, STATE_ALARM_DISARMED,
|
STATE_ALARM_DISARMED, STATE_ALARM_ARMING, STATE_ALARM_DISARMING,
|
||||||
STATE_ALARM_ARMING, STATE_ALARM_DISARMING, STATE_ALARM_TRIGGERED,
|
STATE_ALARM_TRIGGERED, STATE_ALARM_ARMED_CUSTOM_BYPASS)
|
||||||
CONF_NAME, STATE_ALARM_ARMED_CUSTOM_BYPASS)
|
|
||||||
|
from . import DOMAIN as TOTALCONNECT_DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEFAULT_NAME = 'Total Connect'
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up a TotalConnect control panel."""
|
"""Set up an alarm control panel for a TotalConnect device."""
|
||||||
name = config.get(CONF_NAME)
|
if discovery_info is None:
|
||||||
username = config.get(CONF_USERNAME)
|
return
|
||||||
password = config.get(CONF_PASSWORD)
|
|
||||||
|
|
||||||
total_connect = TotalConnect(name, username, password)
|
alarms = []
|
||||||
add_entities([total_connect], True)
|
|
||||||
|
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))
|
||||||
|
add_entities(alarms)
|
||||||
|
|
||||||
|
|
||||||
class TotalConnect(alarm.AlarmControlPanel):
|
class TotalConnectAlarm(alarm.AlarmControlPanel):
|
||||||
"""Represent an TotalConnect status."""
|
"""Represent an TotalConnect status."""
|
||||||
|
|
||||||
def __init__(self, name, username, password):
|
def __init__(self, name, location_id, client):
|
||||||
"""Initialize the TotalConnect status."""
|
"""Initialize the TotalConnect status."""
|
||||||
from total_connect_client import TotalConnectClient
|
|
||||||
|
|
||||||
_LOGGER.debug("Setting up TotalConnect...")
|
|
||||||
self._name = name
|
self._name = name
|
||||||
self._username = username
|
self._location_id = location_id
|
||||||
self._password = password
|
self._client = client
|
||||||
self._state = None
|
self._state = None
|
||||||
self._device_state_attributes = {}
|
self._device_state_attributes = {}
|
||||||
self._client = TotalConnectClient.TotalConnectClient(
|
|
||||||
username, password)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -66,17 +56,36 @@ class TotalConnect(alarm.AlarmControlPanel):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
status = self._client.get_armed_status()
|
status = self._client.get_armed_status(self._name)
|
||||||
attr = {'triggered_source': None, 'triggered_zone': None}
|
attr = {
|
||||||
|
'location_name': self._name,
|
||||||
|
'location_id': self._location_id,
|
||||||
|
'ac_loss': self._client.ac_loss,
|
||||||
|
'low_battery': self._client.low_battery,
|
||||||
|
'triggered_source': None,
|
||||||
|
'triggered_zone': None
|
||||||
|
}
|
||||||
|
|
||||||
if status == self._client.DISARMED:
|
if status == self._client.DISARMED:
|
||||||
state = STATE_ALARM_DISARMED
|
state = STATE_ALARM_DISARMED
|
||||||
|
elif status == self._client.DISARMED_BYPASS:
|
||||||
|
state = STATE_ALARM_DISARMED
|
||||||
elif status == self._client.ARMED_STAY:
|
elif status == self._client.ARMED_STAY:
|
||||||
state = STATE_ALARM_ARMED_HOME
|
state = STATE_ALARM_ARMED_HOME
|
||||||
elif status == self._client.ARMED_AWAY:
|
elif status == self._client.ARMED_STAY_INSTANT:
|
||||||
state = STATE_ALARM_ARMED_AWAY
|
state = STATE_ALARM_ARMED_HOME
|
||||||
|
elif status == self._client.ARMED_STAY_INSTANT_BYPASS:
|
||||||
|
state = STATE_ALARM_ARMED_HOME
|
||||||
elif status == self._client.ARMED_STAY_NIGHT:
|
elif status == self._client.ARMED_STAY_NIGHT:
|
||||||
state = STATE_ALARM_ARMED_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:
|
||||||
|
state = STATE_ALARM_ARMED_AWAY
|
||||||
elif status == self._client.ARMED_CUSTOM_BYPASS:
|
elif status == self._client.ARMED_CUSTOM_BYPASS:
|
||||||
state = STATE_ALARM_ARMED_CUSTOM_BYPASS
|
state = STATE_ALARM_ARMED_CUSTOM_BYPASS
|
||||||
elif status == self._client.ARMING:
|
elif status == self._client.ARMING:
|
||||||
@ -102,16 +111,16 @@ class TotalConnect(alarm.AlarmControlPanel):
|
|||||||
|
|
||||||
def alarm_disarm(self, code=None):
|
def alarm_disarm(self, code=None):
|
||||||
"""Send disarm command."""
|
"""Send disarm command."""
|
||||||
self._client.disarm()
|
self._client.disarm(self._name)
|
||||||
|
|
||||||
def alarm_arm_home(self, code=None):
|
def alarm_arm_home(self, code=None):
|
||||||
"""Send arm home command."""
|
"""Send arm home command."""
|
||||||
self._client.arm_stay()
|
self._client.arm_stay(self._name)
|
||||||
|
|
||||||
def alarm_arm_away(self, code=None):
|
def alarm_arm_away(self, code=None):
|
||||||
"""Send arm away command."""
|
"""Send arm away command."""
|
||||||
self._client.arm_away()
|
self._client.arm_away(self._name)
|
||||||
|
|
||||||
def alarm_arm_night(self, code=None):
|
def alarm_arm_night(self, code=None):
|
||||||
"""Send arm night command."""
|
"""Send arm night command."""
|
||||||
self._client.arm_stay_night()
|
self._client.arm_stay_night(self._name)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Totalconnect",
|
"name": "Totalconnect",
|
||||||
"documentation": "https://www.home-assistant.io/components/totalconnect",
|
"documentation": "https://www.home-assistant.io/components/totalconnect",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"total_connect_client==0.27"
|
"total_connect_client==0.28"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
|
@ -1816,7 +1816,7 @@ todoist-python==7.0.17
|
|||||||
toonapilib==3.2.4
|
toonapilib==3.2.4
|
||||||
|
|
||||||
# homeassistant.components.totalconnect
|
# homeassistant.components.totalconnect
|
||||||
total_connect_client==0.27
|
total_connect_client==0.28
|
||||||
|
|
||||||
# homeassistant.components.tplink_lte
|
# homeassistant.components.tplink_lte
|
||||||
tp-connected==0.0.4
|
tp-connected==0.0.4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user