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

Point alarm control #20972

Merged
merged 7 commits into from Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion homeassistant/components/point/__init__.py
Expand Up @@ -20,7 +20,7 @@
CONF_WEBHOOK_URL, DOMAIN, EVENT_RECEIVED, POINT_DISCOVERY_NEW,
SCAN_INTERVAL, SIGNAL_UPDATE_ENTITY, SIGNAL_WEBHOOK)

REQUIREMENTS = ['pypoint==1.0.8']
REQUIREMENTS = ['pypoint==1.1.1']

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -159,6 +159,7 @@ def __init__(self, hass: HomeAssistantType, config_entry: ConfigEntry,
session):
"""Initialize the Minut data object."""
self._known_devices = set()
self._known_homes = set()
self._hass = hass
self._config_entry = config_entry
self._is_available = True
Expand Down Expand Up @@ -194,6 +195,10 @@ async def new_device(device_id, component):
device_id)

self._is_available = True
for home_id in self._client.homes:
if home_id not in self._known_homes:
await new_device(home_id, 'alarm_control_panel')
self._known_homes.add(home_id)
for device in self._client.devices:
if device.device_id not in self._known_devices:
for component in ('sensor', 'binary_sensor'):
Expand All @@ -213,6 +218,19 @@ def remove_webhook(self):
"""Remove the session webhook."""
return self._client.remove_webhook()

@property
def homes(self):
"""Return known homes."""
return self._client.homes

def alarm_disarm(self, home_id):
"""Send alarm disarm command."""
return self._client.alarm_disarm(home_id)

def alarm_arm(self, home_id):
"""Send alarm arm command."""
return self._client.alarm_arm(home_id)


class MinutPointEntity(Entity):
"""Base Entity used by the sensors."""
Expand Down Expand Up @@ -286,6 +304,7 @@ def device_info(self):
'model': 'Point v{}'.format(device['hardware_version']),
'name': device['description'],
'sw_version': device['firmware']['installed'],
'via_hub': (DOMAIN, device['home']),
}

@property
Expand Down
84 changes: 84 additions & 0 deletions homeassistant/components/point/alarm_control_panel.py
@@ -0,0 +1,84 @@
"""
Support for Minut Point.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/point/
fredrike marked this conversation as resolved.
Show resolved Hide resolved
"""

fredrike marked this conversation as resolved.
Show resolved Hide resolved
import logging

from homeassistant.components.alarm_control_panel import (DOMAIN,
AlarmControlPanel)
from homeassistant.const import (STATE_ALARM_ARMED_AWAY, STATE_ALARM_DISARMED)
from homeassistant.components.point.const import (
DOMAIN as POINT_DOMAIN, POINT_DISCOVERY_NEW)
from homeassistant.helpers.dispatcher import async_dispatcher_connect

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up a Point's alarm_control_panel based on a config entry."""
async def async_discover_home(home_id):
"""Discover and add a discovered home."""
client = hass.data[POINT_DOMAIN][config_entry.entry_id]
async_add_entities([MinutPointAlarmControl(client, home_id)], True)

async_dispatcher_connect(
hass, POINT_DISCOVERY_NEW.format(DOMAIN, POINT_DOMAIN),
async_discover_home)


class MinutPointAlarmControl(AlarmControlPanel):
"""The platform class required by Home Assistant."""

def __init__(self, point_client, home_id):
"""Initialize the entity."""
self._client = point_client
self._home_id = home_id

@property
def _home(self):
"""Return the home object."""
return self._client.homes[self._home_id]

@property
def name(self):
"""Return name of the device."""
return self._home['name']

@property
def state(self):
"""Return state of the device."""
return STATE_ALARM_DISARMED if self._home[
'alarm_status'] == 'off' else STATE_ALARM_ARMED_AWAY
fredrike marked this conversation as resolved.
Show resolved Hide resolved

def alarm_disarm(self, code=None):
"""Send disarm command."""
status = self._client.alarm_disarm(self._home_id)
if status:
self._home['alarm_status'] = 'off'

def alarm_arm_away(self, code=None):
"""Send arm away command."""
status = self._client.alarm_arm(self._home_id)
if status:
self._home['alarm_status'] = 'on'

def alarm_arm_home(self, code=None):
"""Send arm home command."""
self.alarm_arm_away()
fredrike marked this conversation as resolved.
Show resolved Hide resolved

@property
def unique_id(self):
"""Return the unique id of the sensor."""
return 'point.{}-{}'.format(DOMAIN, self._home_id)
fredrike marked this conversation as resolved.
Show resolved Hide resolved

@property
def device_info(self):
"""Return a device description for device registry."""
return {
'identifiers': {(POINT_DOMAIN, self._home_id)},
'name': self.name,
'manufacturer': 'Minut',
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Expand Up @@ -1196,7 +1196,7 @@ pypck==0.5.9
pypjlink2==1.2.0

# homeassistant.components.point
pypoint==1.0.8
pypoint==1.1.1

# homeassistant.components.sensor.pollen
pypollencom==2.2.2
Expand Down