mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
commit
fbb4c43353
@ -171,7 +171,7 @@ class AlexaIntentsView(http.HomeAssistantView):
|
|||||||
|
|
||||||
if 'simple' in intent_response.card:
|
if 'simple' in intent_response.card:
|
||||||
alexa_response.add_card(
|
alexa_response.add_card(
|
||||||
'simple', intent_response.card['simple']['title'],
|
CardType.simple, intent_response.card['simple']['title'],
|
||||||
intent_response.card['simple']['content'])
|
intent_response.card['simple']['content'])
|
||||||
|
|
||||||
return self.json(alexa_response)
|
return self.json(alexa_response)
|
||||||
@ -208,8 +208,8 @@ class AlexaResponse(object):
|
|||||||
self.card = card
|
self.card = card
|
||||||
return
|
return
|
||||||
|
|
||||||
card["title"] = title.async_render(self.variables)
|
card["title"] = title
|
||||||
card["content"] = content.async_render(self.variables)
|
card["content"] = content
|
||||||
self.card = card
|
self.card = card
|
||||||
|
|
||||||
def add_speech(self, speech_type, text):
|
def add_speech(self, speech_type, text):
|
||||||
@ -218,9 +218,6 @@ class AlexaResponse(object):
|
|||||||
|
|
||||||
key = 'ssml' if speech_type == SpeechType.ssml else 'text'
|
key = 'ssml' if speech_type == SpeechType.ssml else 'text'
|
||||||
|
|
||||||
if isinstance(text, template.Template):
|
|
||||||
text = text.async_render(self.variables)
|
|
||||||
|
|
||||||
self.speech = {
|
self.speech = {
|
||||||
'type': speech_type.value,
|
'type': speech_type.value,
|
||||||
key: text
|
key: text
|
||||||
|
@ -27,10 +27,12 @@ def get_device(hass, values, node_config, **kwargs):
|
|||||||
zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL
|
zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL
|
||||||
and values.primary.index == 0):
|
and values.primary.index == 0):
|
||||||
return ZwaveRollershutter(hass, values, invert_buttons)
|
return ZwaveRollershutter(hass, values, invert_buttons)
|
||||||
elif (values.primary.command_class in [
|
elif (values.primary.command_class ==
|
||||||
zwave.const.COMMAND_CLASS_SWITCH_BINARY,
|
zwave.const.COMMAND_CLASS_SWITCH_BINARY):
|
||||||
zwave.const.COMMAND_CLASS_BARRIER_OPERATOR]):
|
return ZwaveGarageDoorSwitch(values)
|
||||||
return ZwaveGarageDoor(values)
|
elif (values.primary.command_class ==
|
||||||
|
zwave.const.COMMAND_CLASS_BARRIER_OPERATOR):
|
||||||
|
return ZwaveGarageDoorBarrier(values)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@ -104,8 +106,8 @@ class ZwaveRollershutter(zwave.ZWaveDeviceEntity, CoverDevice):
|
|||||||
self._network.manager.releaseButton(self._open_id)
|
self._network.manager.releaseButton(self._open_id)
|
||||||
|
|
||||||
|
|
||||||
class ZwaveGarageDoor(zwave.ZWaveDeviceEntity, CoverDevice):
|
class ZwaveGarageDoorBase(zwave.ZWaveDeviceEntity, CoverDevice):
|
||||||
"""Representation of an Zwave garage door device."""
|
"""Base class for a Zwave garage door device."""
|
||||||
|
|
||||||
def __init__(self, values):
|
def __init__(self, values):
|
||||||
"""Initialize the zwave garage door."""
|
"""Initialize the zwave garage door."""
|
||||||
@ -118,6 +120,37 @@ class ZwaveGarageDoor(zwave.ZWaveDeviceEntity, CoverDevice):
|
|||||||
self._state = self.values.primary.data
|
self._state = self.values.primary.data
|
||||||
_LOGGER.debug("self._state=%s", self._state)
|
_LOGGER.debug("self._state=%s", self._state)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the class of this device, from component DEVICE_CLASSES."""
|
||||||
|
return 'garage'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def supported_features(self):
|
||||||
|
"""Flag supported features."""
|
||||||
|
return SUPPORT_GARAGE
|
||||||
|
|
||||||
|
|
||||||
|
class ZwaveGarageDoorSwitch(ZwaveGarageDoorBase):
|
||||||
|
"""Representation of a switch based Zwave garage door device."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_closed(self):
|
||||||
|
"""Return the current position of Zwave garage door."""
|
||||||
|
return not self._state
|
||||||
|
|
||||||
|
def close_cover(self):
|
||||||
|
"""Close the garage door."""
|
||||||
|
self.values.primary.data = False
|
||||||
|
|
||||||
|
def open_cover(self):
|
||||||
|
"""Open the garage door."""
|
||||||
|
self.values.primary.data = True
|
||||||
|
|
||||||
|
|
||||||
|
class ZwaveGarageDoorBarrier(ZwaveGarageDoorBase):
|
||||||
|
"""Representation of a barrier operator Zwave garage door device."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_opening(self):
|
def is_opening(self):
|
||||||
"""Return true if cover is in an opening state."""
|
"""Return true if cover is in an opening state."""
|
||||||
@ -140,13 +173,3 @@ class ZwaveGarageDoor(zwave.ZWaveDeviceEntity, CoverDevice):
|
|||||||
def open_cover(self):
|
def open_cover(self):
|
||||||
"""Open the garage door."""
|
"""Open the garage door."""
|
||||||
self.values.primary.data = "Opened"
|
self.values.primary.data = "Opened"
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the class of this device, from component DEVICE_CLASSES."""
|
|
||||||
return 'garage'
|
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self):
|
|
||||||
"""Flag supported features."""
|
|
||||||
return SUPPORT_GARAGE
|
|
||||||
|
@ -31,7 +31,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
|
|
||||||
def brightness_to_percentage(byt):
|
def brightness_to_percentage(byt):
|
||||||
"""Convert brightness from absolute 0..255 to percentage."""
|
"""Convert brightness from absolute 0..255 to percentage."""
|
||||||
return (byt*100.0)/255.0
|
return int((byt*100.0)/255.0)
|
||||||
|
|
||||||
|
|
||||||
def brightness_from_percentage(percent):
|
def brightness_from_percentage(percent):
|
||||||
@ -53,6 +53,8 @@ class TPLinkSmartBulb(Light):
|
|||||||
self._name = name
|
self._name = name
|
||||||
|
|
||||||
self._state = None
|
self._state = None
|
||||||
|
self._color_temp = None
|
||||||
|
self._brightness = None
|
||||||
_LOGGER.debug("Setting up TP-Link Smart Bulb")
|
_LOGGER.debug("Setting up TP-Link Smart Bulb")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -70,7 +72,6 @@ class TPLinkSmartBulb(Light):
|
|||||||
if ATTR_BRIGHTNESS in kwargs:
|
if ATTR_BRIGHTNESS in kwargs:
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS, self.brightness or 255)
|
brightness = kwargs.get(ATTR_BRIGHTNESS, self.brightness or 255)
|
||||||
self.smartbulb.brightness = brightness_to_percentage(brightness)
|
self.smartbulb.brightness = brightness_to_percentage(brightness)
|
||||||
|
|
||||||
self.smartbulb.state = self.smartbulb.BULB_STATE_ON
|
self.smartbulb.state = self.smartbulb.BULB_STATE_ON
|
||||||
|
|
||||||
def turn_off(self):
|
def turn_off(self):
|
||||||
@ -80,33 +81,31 @@ class TPLinkSmartBulb(Light):
|
|||||||
@property
|
@property
|
||||||
def color_temp(self):
|
def color_temp(self):
|
||||||
"""Return the color temperature of this light in mireds for HA."""
|
"""Return the color temperature of this light in mireds for HA."""
|
||||||
if self.smartbulb.is_color:
|
return self._color_temp
|
||||||
if (self.smartbulb.color_temp is not None and
|
|
||||||
self.smartbulb.color_temp != 0):
|
|
||||||
return kelvin_to_mired(self.smartbulb.color_temp)
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
"""Return the brightness of this light between 0..255."""
|
"""Return the brightness of this light between 0..255."""
|
||||||
return brightness_from_percentage(self.smartbulb.brightness)
|
return self._brightness
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""True if device is on."""
|
"""True if device is on."""
|
||||||
return self.smartbulb.state == \
|
return self._state
|
||||||
self.smartbulb.BULB_STATE_ON
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the TP-Link Bulb's state."""
|
"""Update the TP-Link Bulb's state."""
|
||||||
from pyHS100 import SmartPlugException
|
from pyHS100 import SmartPlugException
|
||||||
try:
|
try:
|
||||||
self._state = self.smartbulb.state == \
|
self._state = (
|
||||||
self.smartbulb.BULB_STATE_ON
|
self.smartbulb.state == self.smartbulb.BULB_STATE_ON)
|
||||||
|
self._brightness = brightness_from_percentage(
|
||||||
|
self.smartbulb.brightness)
|
||||||
|
if self.smartbulb.is_color:
|
||||||
|
if (self.smartbulb.color_temp is not None and
|
||||||
|
self.smartbulb.color_temp != 0):
|
||||||
|
self._color_temp = kelvin_to_mired(
|
||||||
|
self.smartbulb.color_temp)
|
||||||
except (SmartPlugException, OSError) as ex:
|
except (SmartPlugException, OSError) as ex:
|
||||||
_LOGGER.warning('Could not read state for %s: %s', self.name, ex)
|
_LOGGER.warning('Could not read state for %s: %s', self.name, ex)
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ class TradfriGroup(Light):
|
|||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Instruct the group lights to turn off."""
|
"""Instruct the group lights to turn off."""
|
||||||
return self._group.set_state(0)
|
self._group.set_state(0)
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""Instruct the group lights to turn on, or dim."""
|
"""Instruct the group lights to turn on, or dim."""
|
||||||
@ -82,7 +82,11 @@ class TradfriGroup(Light):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Fetch new state data for this group."""
|
"""Fetch new state data for this group."""
|
||||||
|
from pytradfri import RequestTimeout
|
||||||
|
try:
|
||||||
self._group.update()
|
self._group.update()
|
||||||
|
except RequestTimeout:
|
||||||
|
_LOGGER.warning("Tradfri update request timed out")
|
||||||
|
|
||||||
|
|
||||||
class Tradfri(Light):
|
class Tradfri(Light):
|
||||||
@ -153,7 +157,7 @@ class Tradfri(Light):
|
|||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Instruct the light to turn off."""
|
"""Instruct the light to turn off."""
|
||||||
return self._light_control.set_state(False)
|
self._light_control.set_state(False)
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
@ -181,7 +185,11 @@ class Tradfri(Light):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Fetch new state data for this light."""
|
"""Fetch new state data for this light."""
|
||||||
|
from pytradfri import RequestTimeout
|
||||||
|
try:
|
||||||
self._light.update()
|
self._light.update()
|
||||||
|
except RequestTimeout:
|
||||||
|
_LOGGER.warning("Tradfri update request timed out")
|
||||||
|
|
||||||
# Handle Hue lights paired with the gateway
|
# Handle Hue lights paired with the gateway
|
||||||
# hex_color is 0 when bulb is unreachable
|
# hex_color is 0 when bulb is unreachable
|
||||||
|
@ -361,7 +361,7 @@ class KodiDevice(MediaPlayerDevice):
|
|||||||
self._properties = {}
|
self._properties = {}
|
||||||
self._item = {}
|
self._item = {}
|
||||||
self._app_properties = {}
|
self._app_properties = {}
|
||||||
self.hass.async_add_job(self.async_update_ha_state())
|
self.hass.async_add_job(self._ws_server.close())
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _get_players(self):
|
def _get_players(self):
|
||||||
@ -410,6 +410,8 @@ class KodiDevice(MediaPlayerDevice):
|
|||||||
# Kodi abruptly ends ws connection when exiting. We will try
|
# Kodi abruptly ends ws connection when exiting. We will try
|
||||||
# to reconnect on the next poll.
|
# to reconnect on the next poll.
|
||||||
pass
|
pass
|
||||||
|
# Update HA state after Kodi disconnects
|
||||||
|
self.hass.async_add_job(self.async_update_ha_state())
|
||||||
|
|
||||||
# Create a task instead of adding a tracking job, since this task will
|
# Create a task instead of adding a tracking job, since this task will
|
||||||
# run until the websocket connection is closed.
|
# run until the websocket connection is closed.
|
||||||
|
@ -85,14 +85,13 @@ class PioneerDevice(MediaPlayerDevice):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def telnet_command(self, command):
|
def telnet_command(self, command):
|
||||||
"""Establish a telnet connection and sends `command`."""
|
"""Establish a telnet connection and sends command."""
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
telnet = telnetlib.Telnet(self._host,
|
telnet = telnetlib.Telnet(
|
||||||
self._port,
|
self._host, self._port, self._timeout)
|
||||||
self._timeout)
|
except (ConnectionRefusedError, OSError):
|
||||||
except ConnectionRefusedError:
|
_LOGGER.warning("Pioneer %s refused connection", self._name)
|
||||||
_LOGGER.debug("Pioneer %s refused connection", self._name)
|
|
||||||
return
|
return
|
||||||
telnet.write(command.encode("ASCII") + b"\r")
|
telnet.write(command.encode("ASCII") + b"\r")
|
||||||
telnet.read_very_eager() # skip response
|
telnet.read_very_eager() # skip response
|
||||||
@ -105,8 +104,8 @@ class PioneerDevice(MediaPlayerDevice):
|
|||||||
"""Get the latest details from the device."""
|
"""Get the latest details from the device."""
|
||||||
try:
|
try:
|
||||||
telnet = telnetlib.Telnet(self._host, self._port, self._timeout)
|
telnet = telnetlib.Telnet(self._host, self._port, self._timeout)
|
||||||
except ConnectionRefusedError:
|
except (ConnectionRefusedError, OSError):
|
||||||
_LOGGER.debug("Pioneer %s refused connection", self._name)
|
_LOGGER.warning("Pioneer %s refused connection", self._name)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
pwstate = self.telnet_request(telnet, "?P", "PWR")
|
pwstate = self.telnet_request(telnet, "?P", "PWR")
|
||||||
|
@ -37,32 +37,32 @@ DEFAULT_HOST = 'testwifi.here'
|
|||||||
|
|
||||||
MONITORED_CONDITIONS = {
|
MONITORED_CONDITIONS = {
|
||||||
ATTR_CURRENT_VERSION: [
|
ATTR_CURRENT_VERSION: [
|
||||||
'Current Version',
|
['software', 'softwareVersion'],
|
||||||
None,
|
None,
|
||||||
'mdi:checkbox-marked-circle-outline'
|
'mdi:checkbox-marked-circle-outline'
|
||||||
],
|
],
|
||||||
ATTR_NEW_VERSION: [
|
ATTR_NEW_VERSION: [
|
||||||
'New Version',
|
['software', 'updateNewVersion'],
|
||||||
None,
|
None,
|
||||||
'mdi:update'
|
'mdi:update'
|
||||||
],
|
],
|
||||||
ATTR_UPTIME: [
|
ATTR_UPTIME: [
|
||||||
'Uptime',
|
['system', 'uptime'],
|
||||||
'days',
|
'days',
|
||||||
'mdi:timelapse'
|
'mdi:timelapse'
|
||||||
],
|
],
|
||||||
ATTR_LAST_RESTART: [
|
ATTR_LAST_RESTART: [
|
||||||
'Last Network Restart',
|
['system', 'uptime'],
|
||||||
None,
|
None,
|
||||||
'mdi:restart'
|
'mdi:restart'
|
||||||
],
|
],
|
||||||
ATTR_LOCAL_IP: [
|
ATTR_LOCAL_IP: [
|
||||||
'Local IP Address',
|
['wan', 'localIpAddress'],
|
||||||
None,
|
None,
|
||||||
'mdi:access-point-network'
|
'mdi:access-point-network'
|
||||||
],
|
],
|
||||||
ATTR_STATUS: [
|
ATTR_STATUS: [
|
||||||
'Status',
|
['wan', 'online'],
|
||||||
None,
|
None,
|
||||||
'mdi:google'
|
'mdi:google'
|
||||||
]
|
]
|
||||||
@ -80,13 +80,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
"""Set up the Google Wifi sensor."""
|
"""Set up the Google Wifi sensor."""
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
host = config.get(CONF_HOST)
|
host = config.get(CONF_HOST)
|
||||||
|
conditions = config.get(CONF_MONITORED_CONDITIONS)
|
||||||
|
|
||||||
api = GoogleWifiAPI(host)
|
api = GoogleWifiAPI(host, conditions)
|
||||||
|
dev = []
|
||||||
|
for condition in conditions:
|
||||||
|
dev.append(GoogleWifiSensor(hass, api, name, condition))
|
||||||
|
|
||||||
sensors = [GoogleWifiSensor(hass, api, name, condition)
|
add_devices(dev, True)
|
||||||
for condition in config[CONF_MONITORED_CONDITIONS]]
|
|
||||||
|
|
||||||
add_devices(sensors, True)
|
|
||||||
|
|
||||||
|
|
||||||
class GoogleWifiSensor(Entity):
|
class GoogleWifiSensor(Entity):
|
||||||
@ -141,13 +142,13 @@ class GoogleWifiSensor(Entity):
|
|||||||
class GoogleWifiAPI(object):
|
class GoogleWifiAPI(object):
|
||||||
"""Get the latest data and update the states."""
|
"""Get the latest data and update the states."""
|
||||||
|
|
||||||
def __init__(self, host):
|
def __init__(self, host, conditions):
|
||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
uri = 'http://'
|
uri = 'http://'
|
||||||
resource = "{}{}{}".format(uri, host, ENDPOINT)
|
resource = "{}{}{}".format(uri, host, ENDPOINT)
|
||||||
|
|
||||||
self._request = requests.Request('GET', resource).prepare()
|
self._request = requests.Request('GET', resource).prepare()
|
||||||
self.raw_data = None
|
self.raw_data = None
|
||||||
|
self.conditions = conditions
|
||||||
self.data = {
|
self.data = {
|
||||||
ATTR_CURRENT_VERSION: STATE_UNKNOWN,
|
ATTR_CURRENT_VERSION: STATE_UNKNOWN,
|
||||||
ATTR_NEW_VERSION: STATE_UNKNOWN,
|
ATTR_NEW_VERSION: STATE_UNKNOWN,
|
||||||
@ -163,39 +164,49 @@ class GoogleWifiAPI(object):
|
|||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from the router."""
|
"""Get the latest data from the router."""
|
||||||
try:
|
try:
|
||||||
_LOGGER.error("Before request")
|
|
||||||
with requests.Session() as sess:
|
with requests.Session() as sess:
|
||||||
response = sess.send(
|
response = sess.send(
|
||||||
self._request, timeout=10)
|
self._request, timeout=10)
|
||||||
self.raw_data = response.json()
|
self.raw_data = response.json()
|
||||||
_LOGGER.error(self.raw_data)
|
|
||||||
self.data_format()
|
self.data_format()
|
||||||
self.availiable = True
|
self.availiable = True
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_LOGGER.error("Unable to fetch data from Google Wifi")
|
_LOGGER.error('Unable to fetch data from Google Wifi')
|
||||||
self.availiable = False
|
self.availiable = False
|
||||||
self.raw_data = None
|
self.raw_data = None
|
||||||
|
|
||||||
def data_format(self):
|
def data_format(self):
|
||||||
"""Format raw data into easily accessible dict."""
|
"""Format raw data into easily accessible dict."""
|
||||||
for key, value in self.raw_data.items():
|
for attr_key in self.conditions:
|
||||||
if key == 'software':
|
value = MONITORED_CONDITIONS[attr_key]
|
||||||
self.data[ATTR_CURRENT_VERSION] = value['softwareVersion']
|
try:
|
||||||
if value['updateNewVersion'] == '0.0.0.0':
|
primary_key = value[0][0]
|
||||||
self.data[ATTR_NEW_VERSION] = 'Latest'
|
sensor_key = value[0][1]
|
||||||
|
if primary_key in self.raw_data:
|
||||||
|
sensor_value = self.raw_data[primary_key][sensor_key]
|
||||||
|
# Format sensor for better readability
|
||||||
|
if (attr_key == ATTR_NEW_VERSION and
|
||||||
|
sensor_value == '0.0.0.0'):
|
||||||
|
sensor_value = 'Latest'
|
||||||
|
elif attr_key == ATTR_UPTIME:
|
||||||
|
sensor_value /= 3600 * 24
|
||||||
|
elif attr_key == ATTR_LAST_RESTART:
|
||||||
|
last_restart = (dt.now() -
|
||||||
|
timedelta(seconds=sensor_value))
|
||||||
|
sensor_value = last_restart.strftime(('%Y-%m-%d '
|
||||||
|
'%H:%M:%S'))
|
||||||
|
elif attr_key == ATTR_STATUS:
|
||||||
|
if sensor_value:
|
||||||
|
sensor_value = 'Online'
|
||||||
else:
|
else:
|
||||||
self.data[ATTR_NEW_VERSION] = value['updateNewVersion']
|
sensor_value = 'Offline'
|
||||||
elif key == 'system':
|
elif attr_key == ATTR_LOCAL_IP:
|
||||||
self.data[ATTR_UPTIME] = value['uptime'] / (3600 * 24)
|
if not self.raw_data['wan']['online']:
|
||||||
last_restart = dt.now() - timedelta(seconds=value['uptime'])
|
sensor_value = STATE_UNKNOWN
|
||||||
self.data[ATTR_LAST_RESTART] = \
|
|
||||||
last_restart.strftime("%Y-%m-%d %H:%M:%S")
|
self.data[attr_key] = sensor_value
|
||||||
elif key == 'wan':
|
except KeyError:
|
||||||
if value['online']:
|
_LOGGER.error('Router does not support %s field. '
|
||||||
self.data[ATTR_STATUS] = 'Online'
|
'Please remove %s from monitored_conditions.',
|
||||||
else:
|
sensor_key, attr_key)
|
||||||
self.data[ATTR_STATUS] = 'Offline'
|
self.data[attr_key] = STATE_UNKNOWN
|
||||||
if not value['ipAddress']:
|
|
||||||
self.data[ATTR_LOCAL_IP] = STATE_UNKNOWN
|
|
||||||
else:
|
|
||||||
self.data[ATTR_LOCAL_IP] = value['localIpAddress']
|
|
||||||
|
@ -6,7 +6,6 @@ https://home-assistant.io/components/telegram_bot.webhooks/
|
|||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
from functools import partial
|
|
||||||
from ipaddress import ip_network
|
from ipaddress import ip_network
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -70,9 +69,18 @@ def async_setup_platform(hass, config):
|
|||||||
_LOGGER.error("Invalid telegram webhook %s must be https", handler_url)
|
_LOGGER.error("Invalid telegram webhook %s must be https", handler_url)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _try_to_set_webhook():
|
||||||
|
retry_num = 0
|
||||||
|
while retry_num < 3:
|
||||||
|
try:
|
||||||
|
return bot.setWebhook(handler_url, timeout=5)
|
||||||
|
except telegram.error.TimedOut:
|
||||||
|
retry_num += 1
|
||||||
|
_LOGGER.warning("Timeout trying to set webhook (retry #%d)",
|
||||||
|
retry_num)
|
||||||
|
|
||||||
if current_status and current_status['url'] != handler_url:
|
if current_status and current_status['url'] != handler_url:
|
||||||
result = yield from hass.async_add_job(
|
result = yield from hass.async_add_job(_try_to_set_webhook)
|
||||||
partial(bot.setWebhook, handler_url, timeout=10))
|
|
||||||
if result:
|
if result:
|
||||||
_LOGGER.info("Set new telegram webhook %s", handler_url)
|
_LOGGER.info("Set new telegram webhook %s", handler_url)
|
||||||
else:
|
else:
|
||||||
|
@ -345,6 +345,9 @@ INDEX_ALARM_TYPE = 0
|
|||||||
INDEX_ALARM_LEVEL = 1
|
INDEX_ALARM_LEVEL = 1
|
||||||
INDEX_ALARM_ACCESS_CONTROL = 9
|
INDEX_ALARM_ACCESS_CONTROL = 9
|
||||||
|
|
||||||
|
# https://github.com/OpenZWave/open-zwave/blob/de1c0e60edf1d1bee81f1ae54b1f58e66c6fd8ed/cpp/src/command_classes/BarrierOperator.cpp#L69
|
||||||
|
INDEX_BARRIER_OPERATOR_LABEL = 1
|
||||||
|
|
||||||
# https://github.com/OpenZWave/open-zwave/blob/67f180eb565f0054f517ff395c71ecd706f6a837/cpp/src/command_classes/DoorLock.cpp#L77
|
# https://github.com/OpenZWave/open-zwave/blob/67f180eb565f0054f517ff395c71ecd706f6a837/cpp/src/command_classes/DoorLock.cpp#L77
|
||||||
INDEX_DOOR_LOCK_LOCK = 0
|
INDEX_DOOR_LOCK_LOCK = 0
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ DISCOVERY_SCHEMAS = [
|
|||||||
const.DISC_INDEX: [const.INDEX_SWITCH_MULTILEVEL_DIM],
|
const.DISC_INDEX: [const.INDEX_SWITCH_MULTILEVEL_DIM],
|
||||||
const.DISC_OPTIONAL: True,
|
const.DISC_OPTIONAL: True,
|
||||||
}})},
|
}})},
|
||||||
{const.DISC_COMPONENT: 'cover', # Garage Door
|
{const.DISC_COMPONENT: 'cover', # Garage Door Switch
|
||||||
const.DISC_GENERIC_DEVICE_CLASS: [
|
const.DISC_GENERIC_DEVICE_CLASS: [
|
||||||
const.GENERIC_TYPE_SWITCH_MULTILEVEL,
|
const.GENERIC_TYPE_SWITCH_MULTILEVEL,
|
||||||
const.GENERIC_TYPE_ENTRY_CONTROL],
|
const.GENERIC_TYPE_ENTRY_CONTROL],
|
||||||
@ -105,11 +105,36 @@ DISCOVERY_SCHEMAS = [
|
|||||||
const.SPECIFIC_TYPE_SECURE_DOOR],
|
const.SPECIFIC_TYPE_SECURE_DOOR],
|
||||||
const.DISC_VALUES: dict(DEFAULT_VALUES_SCHEMA, **{
|
const.DISC_VALUES: dict(DEFAULT_VALUES_SCHEMA, **{
|
||||||
const.DISC_PRIMARY: {
|
const.DISC_PRIMARY: {
|
||||||
const.DISC_COMMAND_CLASS: [
|
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SWITCH_BINARY],
|
||||||
const.COMMAND_CLASS_BARRIER_OPERATOR,
|
|
||||||
const.COMMAND_CLASS_SWITCH_BINARY],
|
|
||||||
const.DISC_GENRE: const.GENRE_USER,
|
const.DISC_GENRE: const.GENRE_USER,
|
||||||
}})},
|
}})},
|
||||||
|
{const.DISC_COMPONENT: 'cover', # Garage Door Barrier
|
||||||
|
const.DISC_GENERIC_DEVICE_CLASS: [
|
||||||
|
const.GENERIC_TYPE_SWITCH_MULTILEVEL,
|
||||||
|
const.GENERIC_TYPE_ENTRY_CONTROL],
|
||||||
|
const.DISC_SPECIFIC_DEVICE_CLASS: [
|
||||||
|
const.SPECIFIC_TYPE_CLASS_A_MOTOR_CONTROL,
|
||||||
|
const.SPECIFIC_TYPE_CLASS_B_MOTOR_CONTROL,
|
||||||
|
const.SPECIFIC_TYPE_CLASS_C_MOTOR_CONTROL,
|
||||||
|
const.SPECIFIC_TYPE_MOTOR_MULTIPOSITION,
|
||||||
|
const.SPECIFIC_TYPE_SECURE_BARRIER_ADDON,
|
||||||
|
const.SPECIFIC_TYPE_SECURE_DOOR],
|
||||||
|
const.DISC_VALUES: dict(DEFAULT_VALUES_SCHEMA, **{
|
||||||
|
const.DISC_PRIMARY: {
|
||||||
|
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_BARRIER_OPERATOR],
|
||||||
|
const.DISC_INDEX: [const.INDEX_BARRIER_OPERATOR_LABEL],
|
||||||
|
}})},
|
||||||
|
{const.DISC_COMPONENT: 'fan',
|
||||||
|
const.DISC_GENERIC_DEVICE_CLASS: [
|
||||||
|
const.GENERIC_TYPE_SWITCH_MULTILEVEL],
|
||||||
|
const.DISC_SPECIFIC_DEVICE_CLASS: [
|
||||||
|
const.SPECIFIC_TYPE_FAN_SWITCH],
|
||||||
|
const.DISC_VALUES: dict(DEFAULT_VALUES_SCHEMA, **{
|
||||||
|
const.DISC_PRIMARY: {
|
||||||
|
const.DISC_COMMAND_CLASS: [const.COMMAND_CLASS_SWITCH_MULTILEVEL],
|
||||||
|
const.DISC_INDEX: [const.INDEX_SWITCH_MULTILEVEL_LEVEL],
|
||||||
|
const.DISC_TYPE: const.TYPE_BYTE,
|
||||||
|
}})},
|
||||||
{const.DISC_COMPONENT: 'light',
|
{const.DISC_COMPONENT: 'light',
|
||||||
const.DISC_GENERIC_DEVICE_CLASS: [
|
const.DISC_GENERIC_DEVICE_CLASS: [
|
||||||
const.GENERIC_TYPE_SWITCH_MULTILEVEL,
|
const.GENERIC_TYPE_SWITCH_MULTILEVEL,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"""Constants used by Home Assistant components."""
|
"""Constants used by Home Assistant components."""
|
||||||
MAJOR_VERSION = 0
|
MAJOR_VERSION = 0
|
||||||
MINOR_VERSION = 50
|
MINOR_VERSION = 50
|
||||||
PATCH_VERSION = '1'
|
PATCH_VERSION = '2'
|
||||||
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
||||||
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
||||||
REQUIRED_PYTHON_VER = (3, 4, 2)
|
REQUIRED_PYTHON_VER = (3, 4, 2)
|
||||||
|
@ -51,7 +51,7 @@ def run(args: List) -> int:
|
|||||||
req, target=deps_dir, constraints=os.path.join(
|
req, target=deps_dir, constraints=os.path.join(
|
||||||
os.path.dirname(__file__), os.pardir, CONSTRAINT_FILE))
|
os.path.dirname(__file__), os.pardir, CONSTRAINT_FILE))
|
||||||
if not returncode:
|
if not returncode:
|
||||||
print('Aborting scipt, could not install dependency', req)
|
print('Aborting script, could not install dependency', req)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
return script.run(args[1:]) # type: ignore
|
return script.run(args[1:]) # type: ignore
|
||||||
|
@ -32,16 +32,30 @@ def test_get_device_detects_rollershutter(hass, mock_openzwave):
|
|||||||
assert isinstance(device, zwave.ZwaveRollershutter)
|
assert isinstance(device, zwave.ZwaveRollershutter)
|
||||||
|
|
||||||
|
|
||||||
def test_get_device_detects_garagedoor(hass, mock_openzwave):
|
def test_get_device_detects_garagedoor_switch(hass, mock_openzwave):
|
||||||
"""Test device returns garage door."""
|
"""Test device returns garage door."""
|
||||||
node = MockNode()
|
node = MockNode()
|
||||||
value = MockValue(data=0, node=node,
|
value = MockValue(data=False, node=node,
|
||||||
|
command_class=const.COMMAND_CLASS_SWITCH_BINARY)
|
||||||
|
values = MockEntityValues(primary=value, node=node)
|
||||||
|
|
||||||
|
device = zwave.get_device(hass=hass, node=node, values=values,
|
||||||
|
node_config={})
|
||||||
|
assert isinstance(device, zwave.ZwaveGarageDoorSwitch)
|
||||||
|
assert device.device_class == "garage"
|
||||||
|
assert device.supported_features == SUPPORT_OPEN | SUPPORT_CLOSE
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_device_detects_garagedoor_barrier(hass, mock_openzwave):
|
||||||
|
"""Test device returns garage door."""
|
||||||
|
node = MockNode()
|
||||||
|
value = MockValue(data="Closed", node=node,
|
||||||
command_class=const.COMMAND_CLASS_BARRIER_OPERATOR)
|
command_class=const.COMMAND_CLASS_BARRIER_OPERATOR)
|
||||||
values = MockEntityValues(primary=value, node=node)
|
values = MockEntityValues(primary=value, node=node)
|
||||||
|
|
||||||
device = zwave.get_device(hass=hass, node=node, values=values,
|
device = zwave.get_device(hass=hass, node=node, values=values,
|
||||||
node_config={})
|
node_config={})
|
||||||
assert isinstance(device, zwave.ZwaveGarageDoor)
|
assert isinstance(device, zwave.ZwaveGarageDoorBarrier)
|
||||||
assert device.device_class == "garage"
|
assert device.device_class == "garage"
|
||||||
assert device.supported_features == SUPPORT_OPEN | SUPPORT_CLOSE
|
assert device.supported_features == SUPPORT_OPEN | SUPPORT_CLOSE
|
||||||
|
|
||||||
@ -158,7 +172,39 @@ def test_roller_reverse_open_close(hass, mock_openzwave):
|
|||||||
assert value_id == close_value.value_id
|
assert value_id == close_value.value_id
|
||||||
|
|
||||||
|
|
||||||
def test_garage_value_changed(hass, mock_openzwave):
|
def test_switch_garage_value_changed(hass, mock_openzwave):
|
||||||
|
"""Test position changed."""
|
||||||
|
node = MockNode()
|
||||||
|
value = MockValue(data=False, node=node,
|
||||||
|
command_class=const.COMMAND_CLASS_SWITCH_BINARY)
|
||||||
|
values = MockEntityValues(primary=value, node=node)
|
||||||
|
device = zwave.get_device(hass=hass, node=node, values=values,
|
||||||
|
node_config={})
|
||||||
|
|
||||||
|
assert device.is_closed
|
||||||
|
|
||||||
|
value.data = True
|
||||||
|
value_changed(value)
|
||||||
|
assert not device.is_closed
|
||||||
|
|
||||||
|
|
||||||
|
def test_switch_garage_commands(hass, mock_openzwave):
|
||||||
|
"""Test position changed."""
|
||||||
|
node = MockNode()
|
||||||
|
value = MockValue(data=False, node=node,
|
||||||
|
command_class=const.COMMAND_CLASS_SWITCH_BINARY)
|
||||||
|
values = MockEntityValues(primary=value, node=node)
|
||||||
|
device = zwave.get_device(hass=hass, node=node, values=values,
|
||||||
|
node_config={})
|
||||||
|
|
||||||
|
assert value.data is False
|
||||||
|
device.open_cover()
|
||||||
|
assert value.data is True
|
||||||
|
device.close_cover()
|
||||||
|
assert value.data is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_barrier_garage_value_changed(hass, mock_openzwave):
|
||||||
"""Test position changed."""
|
"""Test position changed."""
|
||||||
node = MockNode()
|
node = MockNode()
|
||||||
value = MockValue(data="Closed", node=node,
|
value = MockValue(data="Closed", node=node,
|
||||||
@ -190,7 +236,7 @@ def test_garage_value_changed(hass, mock_openzwave):
|
|||||||
assert device.is_closing
|
assert device.is_closing
|
||||||
|
|
||||||
|
|
||||||
def test_garage_commands(hass, mock_openzwave):
|
def test_barrier_garage_commands(hass, mock_openzwave):
|
||||||
"""Test position changed."""
|
"""Test position changed."""
|
||||||
node = MockNode()
|
node = MockNode()
|
||||||
value = MockValue(data="Closed", node=node,
|
value = MockValue(data="Closed", node=node,
|
||||||
|
@ -26,6 +26,10 @@ MOCK_DATA_NEXT = ('{"software": {"softwareVersion":"next",'
|
|||||||
'"wan": {"localIpAddress":"next", "online":false,'
|
'"wan": {"localIpAddress":"next", "online":false,'
|
||||||
'"ipAddress":false}}')
|
'"ipAddress":false}}')
|
||||||
|
|
||||||
|
MOCK_DATA_MISSING = ('{"software": {},'
|
||||||
|
'"system": {},'
|
||||||
|
'"wan": {}}')
|
||||||
|
|
||||||
|
|
||||||
class TestGoogleWifiSetup(unittest.TestCase):
|
class TestGoogleWifiSetup(unittest.TestCase):
|
||||||
"""Tests for setting up the Google Wifi switch platform."""
|
"""Tests for setting up the Google Wifi switch platform."""
|
||||||
@ -47,9 +51,11 @@ class TestGoogleWifiSetup(unittest.TestCase):
|
|||||||
mock_req.get(resource, status_code=200)
|
mock_req.get(resource, status_code=200)
|
||||||
self.assertTrue(setup_component(self.hass, 'sensor', {
|
self.assertTrue(setup_component(self.hass, 'sensor', {
|
||||||
'sensor': {
|
'sensor': {
|
||||||
'platform': 'google_wifi'
|
'platform': 'google_wifi',
|
||||||
|
'monitored_conditions': ['uptime']
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
assert_setup_component(1, 'sensor')
|
||||||
|
|
||||||
@requests_mock.Mocker()
|
@requests_mock.Mocker()
|
||||||
def test_setup_get(self, mock_req):
|
def test_setup_get(self, mock_req):
|
||||||
@ -95,7 +101,9 @@ class TestGoogleWifiSensor(unittest.TestCase):
|
|||||||
now = datetime(1970, month=1, day=1)
|
now = datetime(1970, month=1, day=1)
|
||||||
with patch('homeassistant.util.dt.now', return_value=now):
|
with patch('homeassistant.util.dt.now', return_value=now):
|
||||||
mock_req.get(resource, text=data, status_code=200)
|
mock_req.get(resource, text=data, status_code=200)
|
||||||
self.api = google_wifi.GoogleWifiAPI("localhost")
|
conditions = google_wifi.MONITORED_CONDITIONS.keys()
|
||||||
|
self.api = google_wifi.GoogleWifiAPI("localhost",
|
||||||
|
conditions)
|
||||||
self.name = NAME
|
self.name = NAME
|
||||||
self.sensor_dict = dict()
|
self.sensor_dict = dict()
|
||||||
for condition, cond_list in google_wifi.MONITORED_CONDITIONS.items():
|
for condition, cond_list in google_wifi.MONITORED_CONDITIONS.items():
|
||||||
@ -188,6 +196,18 @@ class TestGoogleWifiSensor(unittest.TestCase):
|
|||||||
else:
|
else:
|
||||||
self.assertEqual('next', sensor.state)
|
self.assertEqual('next', sensor.state)
|
||||||
|
|
||||||
|
@requests_mock.Mocker()
|
||||||
|
def test_when_api_data_missing(self, mock_req):
|
||||||
|
"""Test state logs an error when data is missing."""
|
||||||
|
self.setup_api(MOCK_DATA_MISSING, mock_req)
|
||||||
|
now = datetime(1970, month=1, day=1)
|
||||||
|
with patch('homeassistant.util.dt.now', return_value=now):
|
||||||
|
for name in self.sensor_dict:
|
||||||
|
sensor = self.sensor_dict[name]['sensor']
|
||||||
|
self.fake_delay(2)
|
||||||
|
sensor.update()
|
||||||
|
self.assertEqual(STATE_UNKNOWN, sensor.state)
|
||||||
|
|
||||||
def test_update_when_unavailiable(self):
|
def test_update_when_unavailiable(self):
|
||||||
"""Test state updates when Google Wifi unavailiable."""
|
"""Test state updates when Google Wifi unavailiable."""
|
||||||
self.api.update = Mock('google_wifi.GoogleWifiAPI.update',
|
self.api.update = Mock('google_wifi.GoogleWifiAPI.update',
|
||||||
|
@ -86,7 +86,12 @@ def alexa_client(loop, hass, test_client):
|
|||||||
"CallServiceIntent": {
|
"CallServiceIntent": {
|
||||||
"speech": {
|
"speech": {
|
||||||
"type": "plain",
|
"type": "plain",
|
||||||
"text": "Service called",
|
"text": "Service called for {{ ZodiacSign }}",
|
||||||
|
},
|
||||||
|
"card": {
|
||||||
|
"type": "simple",
|
||||||
|
"title": "Card title for {{ ZodiacSign }}",
|
||||||
|
"content": "Card content: {{ ZodiacSign }}",
|
||||||
},
|
},
|
||||||
"action": {
|
"action": {
|
||||||
"service": "test.alexa",
|
"service": "test.alexa",
|
||||||
@ -319,6 +324,13 @@ def test_intent_request_calling_service(alexa_client):
|
|||||||
assert call.data.get("entity_id") == ["switch.test"]
|
assert call.data.get("entity_id") == ["switch.test"]
|
||||||
assert call.data.get("hello") == "virgo"
|
assert call.data.get("hello") == "virgo"
|
||||||
|
|
||||||
|
data = yield from req.json()
|
||||||
|
assert data['response']['card']['title'] == 'Card title for virgo'
|
||||||
|
assert data['response']['card']['content'] == 'Card content: virgo'
|
||||||
|
assert data['response']['outputSpeech']['type'] == 'PlainText'
|
||||||
|
assert data['response']['outputSpeech']['text'] == \
|
||||||
|
'Service called for virgo'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_intent_session_ended_request(alexa_client):
|
def test_intent_session_ended_request(alexa_client):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user