mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Maintenance (#4101)
* UPdate ordering, fix typos, and align logger messages * Update import style, fix PEP257 issue, and align logger messages * Updaate import style and align logger messages * Update import style and align logger messages * Update ordering * Update import style and ordering * Update quotes * Make logger messages more clear * Fix indentation
This commit is contained in:
parent
5a2b4a5376
commit
d4b3f56d53
@ -4,23 +4,19 @@ Support for Concord232 alarm control panels.
|
|||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/alarm_control_panel.concord232/
|
https://home-assistant.io/components/alarm_control_panel.concord232/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
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.components.alarm_control_panel import PLATFORM_SCHEMA
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST, CONF_NAME, CONF_PORT,
|
CONF_HOST, CONF_NAME, CONF_PORT, STATE_ALARM_ARMED_AWAY,
|
||||||
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME,
|
STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED, STATE_UNKNOWN)
|
||||||
STATE_ALARM_DISARMED, STATE_UNKNOWN)
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
REQUIREMENTS = ['concord232==0.14']
|
REQUIREMENTS = ['concord232==0.14']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -29,17 +25,17 @@ DEFAULT_HOST = 'localhost'
|
|||||||
DEFAULT_NAME = 'CONCORD232'
|
DEFAULT_NAME = 'CONCORD232'
|
||||||
DEFAULT_PORT = 5007
|
DEFAULT_PORT = 5007
|
||||||
|
|
||||||
|
SCAN_INTERVAL = 1
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||||
vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
|
vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
|
||||||
})
|
})
|
||||||
|
|
||||||
SCAN_INTERVAL = 1
|
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup concord232 platform."""
|
"""Set up the Concord232 alarm control panel platform."""
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
port = config.get(CONF_PORT)
|
port = config.get(CONF_PORT)
|
||||||
@ -49,7 +45,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
try:
|
try:
|
||||||
add_devices([Concord232Alarm(hass, url, name)])
|
add_devices([Concord232Alarm(hass, url, name)])
|
||||||
except requests.exceptions.ConnectionError as ex:
|
except requests.exceptions.ConnectionError as ex:
|
||||||
_LOGGER.error('Unable to connect to Concord232: %s', str(ex))
|
_LOGGER.error("Unable to connect to Concord232: %s", str(ex))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@ -57,7 +53,7 @@ class Concord232Alarm(alarm.AlarmControlPanel):
|
|||||||
"""Represents the Concord232-based alarm panel."""
|
"""Represents the Concord232-based alarm panel."""
|
||||||
|
|
||||||
def __init__(self, hass, url, name):
|
def __init__(self, hass, url, name):
|
||||||
"""Initalize the concord232 alarm panel."""
|
"""Initialize the Concord232 alarm panel."""
|
||||||
from concord232 import client as concord232_client
|
from concord232 import client as concord232_client
|
||||||
|
|
||||||
self._state = STATE_UNKNOWN
|
self._state = STATE_UNKNOWN
|
||||||
@ -68,7 +64,7 @@ class Concord232Alarm(alarm.AlarmControlPanel):
|
|||||||
try:
|
try:
|
||||||
client = concord232_client.Client(self._url)
|
client = concord232_client.Client(self._url)
|
||||||
except requests.exceptions.ConnectionError as ex:
|
except requests.exceptions.ConnectionError as ex:
|
||||||
_LOGGER.error('Unable to connect to Concord232: %s', str(ex))
|
_LOGGER.error("Unable to connect to Concord232: %s", str(ex))
|
||||||
|
|
||||||
self._alarm = client
|
self._alarm = client
|
||||||
self._alarm.partitions = self._alarm.list_partitions()
|
self._alarm.partitions = self._alarm.list_partitions()
|
||||||
@ -100,16 +96,16 @@ class Concord232Alarm(alarm.AlarmControlPanel):
|
|||||||
try:
|
try:
|
||||||
part = self._alarm.list_partitions()[0]
|
part = self._alarm.list_partitions()[0]
|
||||||
except requests.exceptions.ConnectionError as ex:
|
except requests.exceptions.ConnectionError as ex:
|
||||||
_LOGGER.error('Unable to connect to %(host)s: %(reason)s',
|
_LOGGER.error("Unable to connect to %(host)s: %(reason)s",
|
||||||
dict(host=self._url, reason=ex))
|
dict(host=self._url, reason=ex))
|
||||||
newstate = STATE_UNKNOWN
|
newstate = STATE_UNKNOWN
|
||||||
except IndexError:
|
except IndexError:
|
||||||
_LOGGER.error('concord232 reports no partitions')
|
_LOGGER.error("Concord232 reports no partitions")
|
||||||
newstate = STATE_UNKNOWN
|
newstate = STATE_UNKNOWN
|
||||||
|
|
||||||
if part['arming_level'] == "Off":
|
if part['arming_level'] == 'Off':
|
||||||
newstate = STATE_ALARM_DISARMED
|
newstate = STATE_ALARM_DISARMED
|
||||||
elif "Home" in part['arming_level']:
|
elif 'Home' in part['arming_level']:
|
||||||
newstate = STATE_ALARM_ARMED_HOME
|
newstate = STATE_ALARM_ARMED_HOME
|
||||||
else:
|
else:
|
||||||
newstate = STATE_ALARM_ARMED_AWAY
|
newstate = STATE_ALARM_ARMED_AWAY
|
||||||
|
@ -5,25 +5,22 @@ For more details about this platform, please refer to the documentation at
|
|||||||
https://home-assistant.io/components/alarm_control_panel.envisalink/
|
https://home-assistant.io/components/alarm_control_panel.envisalink/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import homeassistant.components.alarm_control_panel as alarm
|
import homeassistant.components.alarm_control_panel as alarm
|
||||||
from homeassistant.components.envisalink import (EVL_CONTROLLER,
|
from homeassistant.components.envisalink import (
|
||||||
EnvisalinkDevice,
|
EVL_CONTROLLER, EnvisalinkDevice, PARTITION_SCHEMA, CONF_CODE, CONF_PANIC,
|
||||||
PARTITION_SCHEMA,
|
CONF_PARTITIONNAME, SIGNAL_PARTITION_UPDATE, SIGNAL_KEYPAD_UPDATE)
|
||||||
CONF_CODE,
|
|
||||||
CONF_PANIC,
|
|
||||||
CONF_PARTITIONNAME,
|
|
||||||
SIGNAL_PARTITION_UPDATE,
|
|
||||||
SIGNAL_KEYPAD_UPDATE)
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED,
|
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED,
|
||||||
STATE_UNKNOWN, STATE_ALARM_TRIGGERED)
|
STATE_UNKNOWN, STATE_ALARM_TRIGGERED)
|
||||||
|
|
||||||
DEPENDENCIES = ['envisalink']
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DEPENDENCIES = ['envisalink']
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Perform the setup for Envisalink alarm panels."""
|
"""Perform the setup for Envisalink alarm panels."""
|
||||||
_configured_partitions = discovery_info['partitions']
|
_configured_partitions = discovery_info['partitions']
|
||||||
_code = discovery_info[CONF_CODE]
|
_code = discovery_info[CONF_CODE]
|
||||||
@ -38,30 +35,30 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
|
|||||||
_panic_type,
|
_panic_type,
|
||||||
EVL_CONTROLLER.alarm_state['partition'][part_num],
|
EVL_CONTROLLER.alarm_state['partition'][part_num],
|
||||||
EVL_CONTROLLER)
|
EVL_CONTROLLER)
|
||||||
add_devices_callback([_device])
|
add_devices([_device])
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class EnvisalinkAlarm(EnvisalinkDevice, alarm.AlarmControlPanel):
|
class EnvisalinkAlarm(EnvisalinkDevice, alarm.AlarmControlPanel):
|
||||||
"""Represents the Envisalink-based alarm panel."""
|
"""Representation of an Envisalink-based alarm panel."""
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
def __init__(self, partition_number, alarm_name,
|
def __init__(self, partition_number, alarm_name, code, panic_type, info,
|
||||||
code, panic_type, info, controller):
|
controller):
|
||||||
"""Initialize the alarm panel."""
|
"""Initialize the alarm panel."""
|
||||||
from pydispatch import dispatcher
|
from pydispatch import dispatcher
|
||||||
self._partition_number = partition_number
|
self._partition_number = partition_number
|
||||||
self._code = code
|
self._code = code
|
||||||
self._panic_type = panic_type
|
self._panic_type = panic_type
|
||||||
_LOGGER.debug('Setting up alarm: ' + alarm_name)
|
_LOGGER.debug("Setting up alarm: %s", alarm_name)
|
||||||
EnvisalinkDevice.__init__(self, alarm_name, info, controller)
|
EnvisalinkDevice.__init__(self, alarm_name, info, controller)
|
||||||
dispatcher.connect(self._update_callback,
|
dispatcher.connect(
|
||||||
signal=SIGNAL_PARTITION_UPDATE,
|
self._update_callback, signal=SIGNAL_PARTITION_UPDATE,
|
||||||
sender=dispatcher.Any)
|
sender=dispatcher.Any)
|
||||||
dispatcher.connect(self._update_callback,
|
dispatcher.connect(
|
||||||
signal=SIGNAL_KEYPAD_UPDATE,
|
self._update_callback, signal=SIGNAL_KEYPAD_UPDATE,
|
||||||
sender=dispatcher.Any)
|
sender=dispatcher.Any)
|
||||||
|
|
||||||
def _update_callback(self, partition):
|
def _update_callback(self, partition):
|
||||||
"""Update HA state, if needed."""
|
"""Update HA state, if needed."""
|
||||||
@ -90,20 +87,20 @@ class EnvisalinkAlarm(EnvisalinkDevice, alarm.AlarmControlPanel):
|
|||||||
def alarm_disarm(self, code=None):
|
def alarm_disarm(self, code=None):
|
||||||
"""Send disarm command."""
|
"""Send disarm command."""
|
||||||
if self._code:
|
if self._code:
|
||||||
EVL_CONTROLLER.disarm_partition(str(code),
|
EVL_CONTROLLER.disarm_partition(
|
||||||
self._partition_number)
|
str(code), self._partition_number)
|
||||||
|
|
||||||
def alarm_arm_home(self, code=None):
|
def alarm_arm_home(self, code=None):
|
||||||
"""Send arm home command."""
|
"""Send arm home command."""
|
||||||
if self._code:
|
if self._code:
|
||||||
EVL_CONTROLLER.arm_stay_partition(str(code),
|
EVL_CONTROLLER.arm_stay_partition(
|
||||||
self._partition_number)
|
str(code), self._partition_number)
|
||||||
|
|
||||||
def alarm_arm_away(self, code=None):
|
def alarm_arm_away(self, code=None):
|
||||||
"""Send arm away command."""
|
"""Send arm away command."""
|
||||||
if self._code:
|
if self._code:
|
||||||
EVL_CONTROLLER.arm_away_partition(str(code),
|
EVL_CONTROLLER.arm_away_partition(
|
||||||
self._partition_number)
|
str(code), self._partition_number)
|
||||||
|
|
||||||
def alarm_trigger(self, code=None):
|
def alarm_trigger(self, code=None):
|
||||||
"""Alarm trigger command. Will be used to trigger a panic alarm."""
|
"""Alarm trigger command. Will be used to trigger a panic alarm."""
|
||||||
|
@ -5,20 +5,16 @@ For more details about this platform, please refer to the documentation at
|
|||||||
https://home-assistant.io/components/binary_sensor.concord232/
|
https://home-assistant.io/components/binary_sensor.concord232/
|
||||||
"""
|
"""
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDevice, PLATFORM_SCHEMA, SENSOR_CLASSES)
|
BinarySensorDevice, PLATFORM_SCHEMA, SENSOR_CLASSES)
|
||||||
from homeassistant.const import (CONF_HOST, CONF_PORT)
|
from homeassistant.const import (CONF_HOST, CONF_PORT)
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
|
|
||||||
REQUIREMENTS = ['concord232==0.14']
|
REQUIREMENTS = ['concord232==0.14']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -27,9 +23,12 @@ CONF_EXCLUDE_ZONES = 'exclude_zones'
|
|||||||
CONF_ZONE_TYPES = 'zone_types'
|
CONF_ZONE_TYPES = 'zone_types'
|
||||||
|
|
||||||
DEFAULT_HOST = 'localhost'
|
DEFAULT_HOST = 'localhost'
|
||||||
|
DEFAULT_NAME = 'Alarm'
|
||||||
DEFAULT_PORT = '5007'
|
DEFAULT_PORT = '5007'
|
||||||
DEFAULT_SSL = False
|
DEFAULT_SSL = False
|
||||||
|
|
||||||
|
SCAN_INTERVAL = 1
|
||||||
|
|
||||||
ZONE_TYPES_SCHEMA = vol.Schema({
|
ZONE_TYPES_SCHEMA = vol.Schema({
|
||||||
cv.positive_int: vol.In(SENSOR_CLASSES),
|
cv.positive_int: vol.In(SENSOR_CLASSES),
|
||||||
})
|
})
|
||||||
@ -42,14 +41,10 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
vol.Optional(CONF_ZONE_TYPES, default={}): ZONE_TYPES_SCHEMA,
|
vol.Optional(CONF_ZONE_TYPES, default={}): ZONE_TYPES_SCHEMA,
|
||||||
})
|
})
|
||||||
|
|
||||||
SCAN_INTERVAL = 1
|
|
||||||
|
|
||||||
DEFAULT_NAME = "Alarm"
|
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-locals
|
# pylint: disable=too-many-locals
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Concord232 binary sensor platform."""
|
"""Set up the Concord232 binary sensor platform."""
|
||||||
from concord232 import client as concord232_client
|
from concord232 import client as concord232_client
|
||||||
|
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
@ -59,24 +54,23 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
sensors = []
|
sensors = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_LOGGER.debug('Initializing Client.')
|
_LOGGER.debug("Initializing Client")
|
||||||
client = concord232_client.Client('http://{}:{}'
|
client = concord232_client.Client('http://{}:{}'.format(host, port))
|
||||||
.format(host, port))
|
|
||||||
client.zones = client.list_zones()
|
client.zones = client.list_zones()
|
||||||
client.last_zone_update = datetime.datetime.now()
|
client.last_zone_update = datetime.datetime.now()
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError as ex:
|
except requests.exceptions.ConnectionError as ex:
|
||||||
_LOGGER.error('Unable to connect to Concord232: %s', str(ex))
|
_LOGGER.error("Unable to connect to Concord232: %s", str(ex))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for zone in client.zones:
|
for zone in client.zones:
|
||||||
_LOGGER.info('Loading Zone found: %s', zone['name'])
|
_LOGGER.info("Loading Zone found: %s", zone['name'])
|
||||||
if zone['number'] not in exclude:
|
if zone['number'] not in exclude:
|
||||||
sensors.append(Concord232ZoneSensor(
|
sensors.append(
|
||||||
hass,
|
Concord232ZoneSensor(
|
||||||
client,
|
hass, client, zone, zone_types.get(zone['number'],
|
||||||
zone,
|
get_opening_type(zone)))
|
||||||
zone_types.get(zone['number'], get_opening_type(zone))))
|
)
|
||||||
|
|
||||||
add_devices(sensors)
|
add_devices(sensors)
|
||||||
|
|
||||||
@ -84,16 +78,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_opening_type(zone):
|
def get_opening_type(zone):
|
||||||
"""Helper function to try to guess sensor type frm name."""
|
"""Helper function to try to guess sensor type from name."""
|
||||||
if "MOTION" in zone["name"]:
|
if 'MOTION' in zone['name']:
|
||||||
return "motion"
|
return 'motion'
|
||||||
if "KEY" in zone["name"]:
|
if 'KEY' in zone['name']:
|
||||||
return "safety"
|
return 'safety'
|
||||||
if "SMOKE" in zone["name"]:
|
if 'SMOKE' in zone['name']:
|
||||||
return "smoke"
|
return 'smoke'
|
||||||
if "WATER" in zone["name"]:
|
if 'WATER' in zone['name']:
|
||||||
return "water"
|
return 'water'
|
||||||
return "opening"
|
return 'opening'
|
||||||
|
|
||||||
|
|
||||||
class Concord232ZoneSensor(BinarySensorDevice):
|
class Concord232ZoneSensor(BinarySensorDevice):
|
||||||
|
@ -13,9 +13,9 @@ from homeassistant.components.notify import (
|
|||||||
ATTR_TARGET, PLATFORM_SCHEMA, BaseNotificationService)
|
ATTR_TARGET, PLATFORM_SCHEMA, BaseNotificationService)
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_SENDER
|
from homeassistant.const import CONF_API_KEY, CONF_SENDER
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
REQUIREMENTS = ['messagebird==1.2.0']
|
REQUIREMENTS = ['messagebird==1.2.0']
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_API_KEY): cv.string,
|
vol.Required(CONF_API_KEY): cv.string,
|
||||||
|
@ -6,14 +6,14 @@ https://home-assistant.io/components/notify.nfandroidtv/
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import (ATTR_TITLE,
|
from homeassistant.components.notify import (
|
||||||
ATTR_TITLE_DEFAULT,
|
ATTR_TITLE, ATTR_TITLE_DEFAULT, ATTR_DATA, BaseNotificationService,
|
||||||
ATTR_DATA,
|
PLATFORM_SCHEMA)
|
||||||
BaseNotificationService,
|
from homeassistant.const import CONF_TIMEOUT
|
||||||
PLATFORM_SCHEMA)
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -24,7 +24,6 @@ CONF_POSITION = 'position'
|
|||||||
CONF_TRANSPARENCY = 'transparency'
|
CONF_TRANSPARENCY = 'transparency'
|
||||||
CONF_COLOR = 'color'
|
CONF_COLOR = 'color'
|
||||||
CONF_INTERRUPT = 'interrupt'
|
CONF_INTERRUPT = 'interrupt'
|
||||||
CONF_TIMEOUT = 'timeout'
|
|
||||||
|
|
||||||
DEFAULT_DURATION = 5
|
DEFAULT_DURATION = 5
|
||||||
DEFAULT_POSITION = 'bottom-right'
|
DEFAULT_POSITION = 'bottom-right'
|
||||||
@ -41,32 +40,32 @@ ATTR_BKGCOLOR = 'bkgcolor'
|
|||||||
ATTR_INTERRUPT = 'interrupt'
|
ATTR_INTERRUPT = 'interrupt'
|
||||||
|
|
||||||
POSITIONS = {
|
POSITIONS = {
|
||||||
"bottom-right": 0,
|
'bottom-right': 0,
|
||||||
"bottom-left": 1,
|
'bottom-left': 1,
|
||||||
"top-right": 2,
|
'top-right': 2,
|
||||||
"top-left": 3,
|
'top-left': 3,
|
||||||
"center": 4,
|
'center': 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
TRANSPARENCIES = {
|
TRANSPARENCIES = {
|
||||||
"default": 0,
|
'default': 0,
|
||||||
"0%": 1,
|
'0%': 1,
|
||||||
"25%": 2,
|
'25%': 2,
|
||||||
"50%": 3,
|
'50%': 3,
|
||||||
"75%": 4,
|
'75%': 4,
|
||||||
"100%": 5,
|
'100%': 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
COLORS = {
|
COLORS = {
|
||||||
"grey": "#607d8b",
|
'grey': '#607d8b',
|
||||||
"black": "#000000",
|
'black': '#000000',
|
||||||
"indigo": "#303F9F",
|
'indigo': '#303F9F',
|
||||||
"green": "#4CAF50",
|
'green': '#4CAF50',
|
||||||
"red": "#F44336",
|
'red': '#F44336',
|
||||||
"cyan": "#00BCD4",
|
'cyan': '#00BCD4',
|
||||||
"teal": "#009688",
|
'teal': '#009688',
|
||||||
"amber": "#FFC107",
|
'amber': '#FFC107',
|
||||||
"pink": "#E91E63",
|
'pink': '#E91E63',
|
||||||
}
|
}
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
@ -95,13 +94,8 @@ def get_service(hass, config):
|
|||||||
interrupt = config.get(CONF_INTERRUPT)
|
interrupt = config.get(CONF_INTERRUPT)
|
||||||
timeout = config.get(CONF_TIMEOUT)
|
timeout = config.get(CONF_TIMEOUT)
|
||||||
|
|
||||||
return NFAndroidTVNotificationService(remoteip,
|
return NFAndroidTVNotificationService(
|
||||||
duration,
|
remoteip, duration, position, transparency, color, interrupt, timeout)
|
||||||
position,
|
|
||||||
transparency,
|
|
||||||
color,
|
|
||||||
interrupt,
|
|
||||||
timeout)
|
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-instance-attributes
|
# pylint: disable=too-many-instance-attributes
|
||||||
@ -109,20 +103,19 @@ class NFAndroidTVNotificationService(BaseNotificationService):
|
|||||||
"""Notification service for Notifications for Android TV."""
|
"""Notification service for Notifications for Android TV."""
|
||||||
|
|
||||||
# pylint: disable=too-many-arguments,too-few-public-methods
|
# pylint: disable=too-many-arguments,too-few-public-methods
|
||||||
def __init__(self, remoteip, duration, position, transparency,
|
def __init__(self, remoteip, duration, position, transparency, color,
|
||||||
color, interrupt, timeout):
|
interrupt, timeout):
|
||||||
"""Initialize the service."""
|
"""Initialize the service."""
|
||||||
self._target = "http://%s:7676" % remoteip
|
self._target = 'http://{}:7676'.format(remoteip)
|
||||||
self._default_duration = duration
|
self._default_duration = duration
|
||||||
self._default_position = position
|
self._default_position = position
|
||||||
self._default_transparency = transparency
|
self._default_transparency = transparency
|
||||||
self._default_color = color
|
self._default_color = color
|
||||||
self._default_interrupt = interrupt
|
self._default_interrupt = interrupt
|
||||||
self._timeout = timeout
|
self._timeout = timeout
|
||||||
self._icon_file = os.path.join(os.path.dirname(__file__), "..",
|
self._icon_file = os.path.join(
|
||||||
"frontend",
|
os.path.dirname(__file__), '..', 'frontend', 'www_static', 'icons',
|
||||||
"www_static", "icons",
|
'favicon-192x192.png')
|
||||||
"favicon-192x192.png")
|
|
||||||
|
|
||||||
# pylint: disable=too-many-branches
|
# pylint: disable=too-many-branches
|
||||||
def send_message(self, message="", **kwargs):
|
def send_message(self, message="", **kwargs):
|
||||||
@ -132,36 +125,36 @@ class NFAndroidTVNotificationService(BaseNotificationService):
|
|||||||
payload = dict(filename=('icon.png',
|
payload = dict(filename=('icon.png',
|
||||||
open(self._icon_file, 'rb'),
|
open(self._icon_file, 'rb'),
|
||||||
'application/octet-stream',
|
'application/octet-stream',
|
||||||
{'Expires': '0'}), type="0",
|
{'Expires': '0'}), type='0',
|
||||||
title=kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT),
|
title=kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT),
|
||||||
msg=message, duration="%i" % self._default_duration,
|
msg=message, duration="%i" % self._default_duration,
|
||||||
position="%i" % POSITIONS.get(self._default_position),
|
position='%i' % POSITIONS.get(self._default_position),
|
||||||
bkgcolor="%s" % COLORS.get(self._default_color),
|
bkgcolor='%s' % COLORS.get(self._default_color),
|
||||||
transparency="%i" % TRANSPARENCIES.get(
|
transparency='%i' % TRANSPARENCIES.get(
|
||||||
self._default_transparency),
|
self._default_transparency),
|
||||||
offset="0", app=ATTR_TITLE_DEFAULT, force="true",
|
offset='0', app=ATTR_TITLE_DEFAULT, force='true',
|
||||||
interrupt="%i" % self._default_interrupt)
|
interrupt='%i' % self._default_interrupt)
|
||||||
|
|
||||||
data = kwargs.get(ATTR_DATA)
|
data = kwargs.get(ATTR_DATA)
|
||||||
if data:
|
if data:
|
||||||
if ATTR_DURATION in data:
|
if ATTR_DURATION in data:
|
||||||
duration = data.get(ATTR_DURATION)
|
duration = data.get(ATTR_DURATION)
|
||||||
try:
|
try:
|
||||||
payload[ATTR_DURATION] = "%i" % int(duration)
|
payload[ATTR_DURATION] = '%i' % int(duration)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_LOGGER.warning("Invalid duration-value: %s",
|
_LOGGER.warning("Invalid duration-value: %s",
|
||||||
str(duration))
|
str(duration))
|
||||||
if ATTR_POSITION in data:
|
if ATTR_POSITION in data:
|
||||||
position = data.get(ATTR_POSITION)
|
position = data.get(ATTR_POSITION)
|
||||||
if position in POSITIONS:
|
if position in POSITIONS:
|
||||||
payload[ATTR_POSITION] = "%i" % POSITIONS.get(position)
|
payload[ATTR_POSITION] = '%i' % POSITIONS.get(position)
|
||||||
else:
|
else:
|
||||||
_LOGGER.warning("Invalid position-value: %s",
|
_LOGGER.warning("Invalid position-value: %s",
|
||||||
str(position))
|
str(position))
|
||||||
if ATTR_TRANSPARENCY in data:
|
if ATTR_TRANSPARENCY in data:
|
||||||
transparency = data.get(ATTR_TRANSPARENCY)
|
transparency = data.get(ATTR_TRANSPARENCY)
|
||||||
if transparency in TRANSPARENCIES:
|
if transparency in TRANSPARENCIES:
|
||||||
payload[ATTR_TRANSPARENCY] = "%i" % TRANSPARENCIES.get(
|
payload[ATTR_TRANSPARENCY] = '%i' % TRANSPARENCIES.get(
|
||||||
transparency)
|
transparency)
|
||||||
else:
|
else:
|
||||||
_LOGGER.warning("Invalid transparency-value: %s",
|
_LOGGER.warning("Invalid transparency-value: %s",
|
||||||
@ -169,22 +162,21 @@ class NFAndroidTVNotificationService(BaseNotificationService):
|
|||||||
if ATTR_COLOR in data:
|
if ATTR_COLOR in data:
|
||||||
color = data.get(ATTR_COLOR)
|
color = data.get(ATTR_COLOR)
|
||||||
if color in COLORS:
|
if color in COLORS:
|
||||||
payload[ATTR_BKGCOLOR] = "%s" % COLORS.get(color)
|
payload[ATTR_BKGCOLOR] = '%s' % COLORS.get(color)
|
||||||
else:
|
else:
|
||||||
_LOGGER.warning("Invalid color-value: %s", str(color))
|
_LOGGER.warning("Invalid color-value: %s", str(color))
|
||||||
if ATTR_INTERRUPT in data:
|
if ATTR_INTERRUPT in data:
|
||||||
interrupt = data.get(ATTR_INTERRUPT)
|
interrupt = data.get(ATTR_INTERRUPT)
|
||||||
try:
|
try:
|
||||||
payload[ATTR_INTERRUPT] = "%i" % cv.boolean(interrupt)
|
payload[ATTR_INTERRUPT] = '%i' % cv.boolean(interrupt)
|
||||||
except vol.Invalid:
|
except vol.Invalid:
|
||||||
_LOGGER.warning("Invalid interrupt-value: %s",
|
_LOGGER.warning("Invalid interrupt-value: %s",
|
||||||
str(interrupt))
|
str(interrupt))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_LOGGER.debug("Payload: %s", str(payload))
|
_LOGGER.debug("Payload: %s", str(payload))
|
||||||
response = requests.post(self._target,
|
response = requests.post(
|
||||||
files=payload,
|
self._target, files=payload, timeout=self._timeout)
|
||||||
timeout=self._timeout)
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
_LOGGER.error("Error sending message: %s", str(response))
|
_LOGGER.error("Error sending message: %s", str(response))
|
||||||
except requests.exceptions.ConnectionError as err:
|
except requests.exceptions.ConnectionError as err:
|
||||||
|
@ -9,12 +9,13 @@ import logging
|
|||||||
import requests
|
import requests
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.notify import (BaseNotificationService,
|
from homeassistant.components.notify import (
|
||||||
ATTR_TITLE,
|
BaseNotificationService, ATTR_TITLE, PLATFORM_SCHEMA)
|
||||||
PLATFORM_SCHEMA)
|
|
||||||
from homeassistant.const import CONTENT_TYPE_JSON
|
from homeassistant.const import CONTENT_TYPE_JSON
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONF_CONSUMER_KEY = 'consumer_key'
|
CONF_CONSUMER_KEY = 'consumer_key'
|
||||||
CONF_CONSUMER_SECRET = 'consumer_secret'
|
CONF_CONSUMER_SECRET = 'consumer_secret'
|
||||||
CONF_PHONE_NUMBER = 'phone_number'
|
CONF_PHONE_NUMBER = 'phone_number'
|
||||||
@ -25,8 +26,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
vol.Required(CONF_PHONE_NUMBER): cv.string,
|
vol.Required(CONF_PHONE_NUMBER): cv.string,
|
||||||
})
|
})
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def get_service(hass, config):
|
def get_service(hass, config):
|
||||||
"""Get the Telstra SMS API notification service."""
|
"""Get the Telstra SMS API notification service."""
|
||||||
@ -34,14 +33,12 @@ def get_service(hass, config):
|
|||||||
consumer_secret = config.get(CONF_CONSUMER_SECRET)
|
consumer_secret = config.get(CONF_CONSUMER_SECRET)
|
||||||
phone_number = config.get(CONF_PHONE_NUMBER)
|
phone_number = config.get(CONF_PHONE_NUMBER)
|
||||||
|
|
||||||
# Attempt an initial authentication to confirm credentials
|
|
||||||
if _authenticate(consumer_key, consumer_secret) is False:
|
if _authenticate(consumer_key, consumer_secret) is False:
|
||||||
_LOGGER.exception('Error obtaining authorization from Telstra API')
|
_LOGGER.exception('Error obtaining authorization from Telstra API')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return TelstraNotificationService(consumer_key,
|
return TelstraNotificationService(
|
||||||
consumer_secret,
|
consumer_key, consumer_secret, phone_number)
|
||||||
phone_number)
|
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods, too-many-arguments
|
# pylint: disable=too-few-public-methods, too-many-arguments
|
||||||
@ -59,10 +56,10 @@ class TelstraNotificationService(BaseNotificationService):
|
|||||||
title = kwargs.get(ATTR_TITLE)
|
title = kwargs.get(ATTR_TITLE)
|
||||||
|
|
||||||
# Retrieve authorization first
|
# Retrieve authorization first
|
||||||
token_response = _authenticate(self._consumer_key,
|
token_response = _authenticate(
|
||||||
self._consumer_secret)
|
self._consumer_key, self._consumer_secret)
|
||||||
if token_response is False:
|
if token_response is False:
|
||||||
_LOGGER.exception('Error obtaining authorization from Telstra API')
|
_LOGGER.exception("Error obtaining authorization from Telstra API")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Send the SMS
|
# Send the SMS
|
||||||
@ -73,17 +70,16 @@ class TelstraNotificationService(BaseNotificationService):
|
|||||||
|
|
||||||
message_data = {
|
message_data = {
|
||||||
'to': self._phone_number,
|
'to': self._phone_number,
|
||||||
'body': text
|
'body': text,
|
||||||
}
|
}
|
||||||
message_resource = 'https://api.telstra.com/v1/sms/messages'
|
message_resource = 'https://api.telstra.com/v1/sms/messages'
|
||||||
message_headers = {
|
message_headers = {
|
||||||
'Content-Type': CONTENT_TYPE_JSON,
|
'Content-Type': CONTENT_TYPE_JSON,
|
||||||
'Authorization': 'Bearer ' + token_response['access_token']
|
'Authorization': 'Bearer ' + token_response['access_token'],
|
||||||
}
|
}
|
||||||
message_response = requests.post(message_resource,
|
message_response = requests.post(
|
||||||
headers=message_headers,
|
message_resource, headers=message_headers, json=message_data,
|
||||||
json=message_data,
|
timeout=10)
|
||||||
timeout=10)
|
|
||||||
|
|
||||||
if message_response.status_code != 202:
|
if message_response.status_code != 202:
|
||||||
_LOGGER.exception("Failed to send SMS. Status code: %d",
|
_LOGGER.exception("Failed to send SMS. Status code: %d",
|
||||||
@ -99,9 +95,8 @@ def _authenticate(consumer_key, consumer_secret):
|
|||||||
'scope': 'SMS'
|
'scope': 'SMS'
|
||||||
}
|
}
|
||||||
token_resource = 'https://api.telstra.com/v1/oauth/token'
|
token_resource = 'https://api.telstra.com/v1/oauth/token'
|
||||||
token_response = requests.get(token_resource,
|
token_response = requests.get(
|
||||||
params=token_data,
|
token_resource, params=token_data, timeout=10).json()
|
||||||
timeout=10).json()
|
|
||||||
|
|
||||||
if 'error' in token_response:
|
if 'error' in token_response:
|
||||||
return False
|
return False
|
||||||
|
@ -9,16 +9,17 @@ import logging
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components.notify import (PLATFORM_SCHEMA,
|
from homeassistant.components.notify import (
|
||||||
BaseNotificationService)
|
PLATFORM_SCHEMA, BaseNotificationService)
|
||||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
from homeassistant.const import CONF_ACCESS_TOKEN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
|
||||||
REQUIREMENTS = ['TwitterAPI==2.4.2']
|
REQUIREMENTS = ['TwitterAPI==2.4.2']
|
||||||
|
|
||||||
CONF_CONSUMER_KEY = "consumer_key"
|
_LOGGER = logging.getLogger(__name__)
|
||||||
CONF_CONSUMER_SECRET = "consumer_secret"
|
|
||||||
CONF_ACCESS_TOKEN_SECRET = "access_token_secret"
|
CONF_CONSUMER_KEY = 'consumer_key'
|
||||||
|
CONF_CONSUMER_SECRET = 'consumer_secret'
|
||||||
|
CONF_ACCESS_TOKEN_SECRET = 'access_token_secret'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_CONSUMER_KEY): cv.string,
|
vol.Required(CONF_CONSUMER_KEY): cv.string,
|
||||||
@ -30,15 +31,15 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
|
|
||||||
def get_service(hass, config):
|
def get_service(hass, config):
|
||||||
"""Get the Twitter notification service."""
|
"""Get the Twitter notification service."""
|
||||||
return TwitterNotificationService(config[CONF_CONSUMER_KEY],
|
return TwitterNotificationService(
|
||||||
config[CONF_CONSUMER_SECRET],
|
config[CONF_CONSUMER_KEY], config[CONF_CONSUMER_SECRET],
|
||||||
config[CONF_ACCESS_TOKEN],
|
config[CONF_ACCESS_TOKEN], config[CONF_ACCESS_TOKEN_SECRET]
|
||||||
config[CONF_ACCESS_TOKEN_SECRET])
|
)
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-few-public-methods
|
# pylint: disable=too-few-public-methods
|
||||||
class TwitterNotificationService(BaseNotificationService):
|
class TwitterNotificationService(BaseNotificationService):
|
||||||
"""Implement notification service for the Twitter service."""
|
"""Implementation of a notification service for the Twitter service."""
|
||||||
|
|
||||||
def __init__(self, consumer_key, consumer_secret, access_token_key,
|
def __init__(self, consumer_key, consumer_secret, access_token_key,
|
||||||
access_token_secret):
|
access_token_secret):
|
||||||
|
@ -9,15 +9,15 @@ import logging
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components.notify import (BaseNotificationService,
|
from homeassistant.components.notify import (
|
||||||
PLATFORM_SCHEMA)
|
BaseNotificationService, PLATFORM_SCHEMA)
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
REQUIREMENTS = ['https://github.com/TheRealLink/pylgtv/archive/v0.1.2.zip'
|
||||||
REQUIREMENTS = ['https://github.com/TheRealLink/pylgtv'
|
|
||||||
'/archive/v0.1.2.zip'
|
|
||||||
'#pylgtv==0.1.2']
|
'#pylgtv==0.1.2']
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_HOST): cv.string,
|
vol.Required(CONF_HOST): cv.string,
|
||||||
@ -34,10 +34,10 @@ def get_service(hass, config):
|
|||||||
try:
|
try:
|
||||||
client.register()
|
client.register()
|
||||||
except PyLGTVPairException:
|
except PyLGTVPairException:
|
||||||
_LOGGER.error('Pairing failed.')
|
_LOGGER.error("Pairing with TV failed")
|
||||||
return None
|
return None
|
||||||
except OSError:
|
except OSError:
|
||||||
_LOGGER.error('Host unreachable.')
|
_LOGGER.error("TV unreachable")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return LgWebOSNotificationService(client)
|
return LgWebOSNotificationService(client)
|
||||||
@ -58,6 +58,6 @@ class LgWebOSNotificationService(BaseNotificationService):
|
|||||||
try:
|
try:
|
||||||
self._client.send_message(message)
|
self._client.send_message(message)
|
||||||
except PyLGTVPairException:
|
except PyLGTVPairException:
|
||||||
_LOGGER.error('Pairing failed.')
|
_LOGGER.error("Pairing with TV failed")
|
||||||
except OSError:
|
except OSError:
|
||||||
_LOGGER.error('Host unreachable.')
|
_LOGGER.error("TV unreachable")
|
||||||
|
@ -53,7 +53,7 @@ class XmppNotificationService(BaseNotificationService):
|
|||||||
def send_message(self, message="", **kwargs):
|
def send_message(self, message="", **kwargs):
|
||||||
"""Send a message to a user."""
|
"""Send a message to a user."""
|
||||||
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
|
||||||
data = "{}: {}".format(title, message) if title else message
|
data = '{}: {}'.format(title, message) if title else message
|
||||||
|
|
||||||
send_message(self._sender + '/home-assistant', self._password,
|
send_message(self._sender + '/home-assistant', self._password,
|
||||||
self._recipient, self._tls, data)
|
self._recipient, self._tls, data)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user