Adding AlarmDecoder platform (#6900)
* Added AlarmDecoder platform * remove try/catch for generic execption * Changes for @pvizeli, thanks for the review! Removed _ prefix from normal function variables Removed _hass as it will be set via .hass for us Broke out the three config (socket, serial, usb) and use vol.Any Added support for USB I think, don't have device, but should work Removed components dictionary, was form old group all code that didn't work * Fix hass string handling
This commit is contained in:
1 parent
9d20a17642
commit
f68542ba0d
6 files changed
+494
No files matched your search
@@ -0,0 +1,75 @@
|
||||
"""
|
||||
Support for AlarmDecoder Sensors (Shows Panel Display).
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.alarmdecoder/
|
||||
"""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from homeassistant.components.alarmdecoder import (SIGNAL_PANEL_MESSAGE)
|
||||
|
||||
from homeassistant.const import (STATE_UNKNOWN)
|
||||
|
||||
DEPENDENCIES = ['alarmdecoder']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||
"""Perform the setup for AlarmDecoder sensor devices."""
|
||||
_LOGGER.debug("AlarmDecoderSensor: async_setup_platform")
|
||||
|
||||
device = AlarmDecoderSensor(hass)
|
||||
|
||||
async_add_devices([device])
|
||||
|
||||
|
||||
class AlarmDecoderSensor(Entity):
|
||||
"""Representation of an AlarmDecoder keypad."""
|
||||
|
||||
def __init__(self, hass):
|
||||
"""Initialize the alarm panel."""
|
||||
self._display = ""
|
||||
self._state = STATE_UNKNOWN
|
||||
self._icon = 'mdi:alarm-check'
|
||||
self._name = 'Alarm Panel Display'
|
||||
|
||||
_LOGGER.debug("AlarmDecoderSensor: Setting up panel")
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_PANEL_MESSAGE, self._message_callback)
|
||||
|
||||
@callback
|
||||
def _message_callback(self, message):
|
||||
if self._display != message.text:
|
||||
self._display = message.text
|
||||
self.hass.async_add_job(self.async_update_ha_state())
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon if any."""
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the overall state."""
|
||||
return self._display
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
Reference in new issue
Block a user