changed to python-verisure 0.4.1

This commit is contained in:
Per Sandström 2015-12-25 20:16:51 +01:00
parent bc4ab4d70a
commit b83b36274a
6 changed files with 72 additions and 77 deletions

View File

@ -29,7 +29,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
alarms.extend([ alarms.extend([
VerisureAlarm(value) VerisureAlarm(value)
for value in verisure.get_alarm_status().values() for value in verisure.ALARM_STATUS.values()
if verisure.SHOW_ALARM if verisure.SHOW_ALARM
]) ])
@ -42,7 +42,6 @@ class VerisureAlarm(alarm.AlarmControlPanel):
def __init__(self, alarm_status): def __init__(self, alarm_status):
self._id = alarm_status.id self._id = alarm_status.id
self._device = verisure.MY_PAGES.DEVICE_ALARM
self._state = STATE_UNKNOWN self._state = STATE_UNKNOWN
@property @property
@ -62,36 +61,36 @@ class VerisureAlarm(alarm.AlarmControlPanel):
def update(self): def update(self):
""" Update alarm status """ """ Update alarm status """
verisure.update() verisure.update_alarm()
if verisure.STATUS[self._device][self._id].status == 'unarmed': if verisure.ALARM_STATUS[self._id].status == 'unarmed':
self._state = STATE_ALARM_DISARMED self._state = STATE_ALARM_DISARMED
elif verisure.STATUS[self._device][self._id].status == 'armedhome': elif verisure.ALARM_STATUS[self._id].status == 'armedhome':
self._state = STATE_ALARM_ARMED_HOME self._state = STATE_ALARM_ARMED_HOME
elif verisure.STATUS[self._device][self._id].status == 'armedaway': elif verisure.ALARM_STATUS[self._id].status == 'armedaway':
self._state = STATE_ALARM_ARMED_AWAY self._state = STATE_ALARM_ARMED_AWAY
elif verisure.STATUS[self._device][self._id].status != 'pending': elif verisure.ALARM_STATUS[self._id].status != 'pending':
_LOGGER.error( _LOGGER.error(
'Unknown alarm state %s', 'Unknown alarm state %s',
verisure.STATUS[self._device][self._id].status) verisure.ALARM_STATUS[self._id].status)
def alarm_disarm(self, code=None): def alarm_disarm(self, code=None):
""" Send disarm command. """ """ Send disarm command. """
verisure.MY_PAGES.set_alarm_status( verisure.MY_PAGES.alarm.set(code, 'DISARMED')
code, verisure.MY_PAGES.alarm.wait_while_pending()
verisure.MY_PAGES.ALARM_DISARMED) verisure.update_alarm()
_LOGGER.warning('disarming') _LOGGER.info('disarming verisure alarm')
def alarm_arm_home(self, code=None): def alarm_arm_home(self, code=None):
""" Send arm home command. """ """ Send arm home command. """
verisure.MY_PAGES.set_alarm_status( verisure.MY_PAGES.alarm.set(code, 'ARMED_HOME')
code, verisure.MY_PAGES.alarm.wait_while_pending()
verisure.MY_PAGES.ALARM_ARMED_HOME) verisure.update_alarm()
_LOGGER.warning('arming home') _LOGGER.info('arming home verisure alarm')
def alarm_arm_away(self, code=None): def alarm_arm_away(self, code=None):
""" Send arm away command. """ """ Send arm away command. """
verisure.MY_PAGES.set_alarm_status( verisure.MY_PAGES.alarm.set(code, 'ARMED_AWAY')
code, verisure.MY_PAGES.alarm.wait_while_pending()
verisure.MY_PAGES.ALARM_ARMED_AWAY) verisure.update_alarm()
_LOGGER.warning('arming away') _LOGGER.info('arming away')

View File

@ -154,6 +154,7 @@ def mute_volume(hass, mute, entity_id=None):
def set_volume_level(hass, volume, entity_id=None): def set_volume_level(hass, volume, entity_id=None):
""" Send the media player the command for volume down. """ """ Send the media player the command for volume down. """
print("AAAAAAAAAAAAAAAAAAAA")
data = {ATTR_MEDIA_VOLUME_LEVEL: volume} data = {ATTR_MEDIA_VOLUME_LEVEL: volume}
if entity_id: if entity_id:
@ -231,9 +232,11 @@ def setup(hass, config):
def volume_set_service(service): def volume_set_service(service):
""" Set specified volume on the media player. """ """ Set specified volume on the media player. """
print(service.data)
target_players = component.extract_from_service(service) target_players = component.extract_from_service(service)
if ATTR_MEDIA_VOLUME_LEVEL not in service.data: if ATTR_MEDIA_VOLUME_LEVEL not in service.data:
print('returning')
return return
volume = service.data[ATTR_MEDIA_VOLUME_LEVEL] volume = service.data[ATTR_MEDIA_VOLUME_LEVEL]

View File

@ -27,14 +27,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
sensors.extend([ sensors.extend([
VerisureThermometer(value) VerisureThermometer(value)
for value in verisure.get_climate_status().values() for value in verisure.CLIMATE_STATUS.values()
if verisure.SHOW_THERMOMETERS and if verisure.SHOW_THERMOMETERS and
hasattr(value, 'temperature') and value.temperature hasattr(value, 'temperature') and value.temperature
]) ])
sensors.extend([ sensors.extend([
VerisureHygrometer(value) VerisureHygrometer(value)
for value in verisure.get_climate_status().values() for value in verisure.CLIMATE_STATUS.values()
if verisure.SHOW_HYGROMETERS and if verisure.SHOW_HYGROMETERS and
hasattr(value, 'humidity') and value.humidity hasattr(value, 'humidity') and value.humidity
]) ])
@ -47,20 +47,19 @@ class VerisureThermometer(Entity):
def __init__(self, climate_status): def __init__(self, climate_status):
self._id = climate_status.id self._id = climate_status.id
self._device = verisure.MY_PAGES.DEVICE_CLIMATE
@property @property
def name(self): def name(self):
""" Returns the name of the device. """ """ Returns the name of the device. """
return '{} {}'.format( return '{} {}'.format(
verisure.STATUS[self._device][self._id].location, verisure.CLIMATE_STATUS[self._id].location,
"Temperature") "Temperature")
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """ Returns the state of the device. """
# remove ° character # remove ° character
return verisure.STATUS[self._device][self._id].temperature[:-1] return verisure.CLIMATE_STATUS[self._id].temperature[:-1]
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
@ -69,7 +68,7 @@ class VerisureThermometer(Entity):
def update(self): def update(self):
''' update sensor ''' ''' update sensor '''
verisure.update() verisure.update_climate()
class VerisureHygrometer(Entity): class VerisureHygrometer(Entity):
@ -77,20 +76,19 @@ class VerisureHygrometer(Entity):
def __init__(self, climate_status): def __init__(self, climate_status):
self._id = climate_status.id self._id = climate_status.id
self._device = verisure.MY_PAGES.DEVICE_CLIMATE
@property @property
def name(self): def name(self):
""" Returns the name of the device. """ """ Returns the name of the device. """
return '{} {}'.format( return '{} {}'.format(
verisure.STATUS[self._device][self._id].location, verisure.CLIMATE_STATUS[self._id].location,
"Humidity") "Humidity")
@property @property
def state(self): def state(self):
""" Returns the state of the device. """ """ Returns the state of the device. """
# remove % character # remove % character
return verisure.STATUS[self._device][self._id].humidity[:-1] return verisure.CLIMATE_STATUS[self._id].humidity[:-1]
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):
@ -99,4 +97,4 @@ class VerisureHygrometer(Entity):
def update(self): def update(self):
''' update sensor ''' ''' update sensor '''
verisure.update() verisure.update_climate()

View File

@ -25,7 +25,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
switches.extend([ switches.extend([
VerisureSmartplug(value) VerisureSmartplug(value)
for value in verisure.get_smartplug_status().values() for value in verisure.SMARTPLUG_STATUS.values()
if verisure.SHOW_SMARTPLUGS if verisure.SHOW_SMARTPLUGS
]) ])
@ -36,31 +36,29 @@ class VerisureSmartplug(SwitchDevice):
""" Represents a Verisure smartplug. """ """ Represents a Verisure smartplug. """
def __init__(self, smartplug_status): def __init__(self, smartplug_status):
self._id = smartplug_status.id self._id = smartplug_status.id
self.status_on = verisure.MY_PAGES.SMARTPLUG_ON
self.status_off = verisure.MY_PAGES.SMARTPLUG_OFF
@property @property
def name(self): def name(self):
""" Get the name (location) of the smartplug. """ """ Get the name (location) of the smartplug. """
return verisure.get_smartplug_status()[self._id].location return verisure.SMARTPLUG_STATUS[self._id].location
@property @property
def is_on(self): def is_on(self):
""" Returns True if on """ """ Returns True if on """
plug_status = verisure.get_smartplug_status()[self._id].status plug_status = verisure.SMARTPLUG_STATUS[self._id].status
return plug_status == self.status_on return plug_status == 'on'
def turn_on(self): def turn_on(self):
""" Set smartplug status on. """ """ Set smartplug status on. """
verisure.MY_PAGES.set_smartplug_status( verisure.MY_PAGES.smartplug.set(self._id, 'on')
self._id, verisure.MY_PAGES.smartplug.wait_while_updating(self._id, 'on')
self.status_on) verisure.update_smartplug()
def turn_off(self): def turn_off(self):
""" Set smartplug status off. """ """ Set smartplug status off. """
verisure.MY_PAGES.set_smartplug_status( verisure.MY_PAGES.smartplug.set(self._id, 'off')
self._id, verisure.MY_PAGES.smartplug.wait_while_updating(self._id, 'off')
self.status_off) verisure.update_smartplug()
def update(self): def update(self):
verisure.update() verisure.update_smartplug()

View File

@ -7,6 +7,8 @@ For more details about this component, please refer to the documentation at
https://home-assistant.io/components/verisure/ https://home-assistant.io/components/verisure/
""" """
import logging import logging
import time
from datetime import timedelta from datetime import timedelta
from homeassistant import bootstrap from homeassistant import bootstrap
@ -28,13 +30,15 @@ DISCOVER_ALARMS = 'verisure.alarm_control_panel'
DEPENDENCIES = ['alarm_control_panel'] DEPENDENCIES = ['alarm_control_panel']
REQUIREMENTS = [ REQUIREMENTS = [
'https://github.com/persandstrom/python-verisure/archive/' 'https://github.com/persandstrom/python-verisure/archive/'
'9873c4527f01b1ba1f72ae60f7f35854390d59be.zip#python-verisure==0.2.6' '0f53c1d6a9e370566a78e36093b02fbd5144b75d.zip#python-verisure==0.4.1'
] ]
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
MY_PAGES = None MY_PAGES = None
STATUS = {} ALARM_STATUS = {}
SMARTPLUG_STATUS = {}
CLIMATE_STATUS = {}
VERISURE_LOGIN_ERROR = None VERISURE_LOGIN_ERROR = None
VERISURE_ERROR = None VERISURE_ERROR = None
@ -47,7 +51,7 @@ SHOW_SMARTPLUGS = True
# if wrong password was given don't try again # if wrong password was given don't try again
WRONG_PASSWORD_GIVEN = False WRONG_PASSWORD_GIVEN = False
MIN_TIME_BETWEEN_REQUESTS = timedelta(seconds=5) MIN_TIME_BETWEEN_REQUESTS = timedelta(seconds=1)
def setup(hass, config): def setup(hass, config):
@ -60,10 +64,6 @@ def setup(hass, config):
from verisure import MyPages, LoginError, Error from verisure import MyPages, LoginError, Error
STATUS[MyPages.DEVICE_ALARM] = {}
STATUS[MyPages.DEVICE_CLIMATE] = {}
STATUS[MyPages.DEVICE_SMARTPLUG] = {}
global SHOW_THERMOMETERS, SHOW_HYGROMETERS, SHOW_ALARM, SHOW_SMARTPLUGS global SHOW_THERMOMETERS, SHOW_HYGROMETERS, SHOW_ALARM, SHOW_SMARTPLUGS
SHOW_THERMOMETERS = int(config[DOMAIN].get('thermometers', '1')) SHOW_THERMOMETERS = int(config[DOMAIN].get('thermometers', '1'))
SHOW_HYGROMETERS = int(config[DOMAIN].get('hygrometers', '1')) SHOW_HYGROMETERS = int(config[DOMAIN].get('hygrometers', '1'))
@ -84,7 +84,9 @@ def setup(hass, config):
_LOGGER.error('Could not log in to verisure mypages, %s', ex) _LOGGER.error('Could not log in to verisure mypages, %s', ex)
return False return False
update() update_alarm()
update_climate()
update_smartplug()
# Load components for the devices in the ISY controller that we support # Load components for the devices in the ISY controller that we support
for comp_name, discovery in ((('sensor', DISCOVER_SENSORS), for comp_name, discovery in ((('sensor', DISCOVER_SENSORS),
@ -101,24 +103,10 @@ def setup(hass, config):
return True return True
def get_alarm_status():
""" Return a list of status overviews for alarm components. """
return STATUS[MY_PAGES.DEVICE_ALARM]
def get_climate_status():
""" Return a list of status overviews for alarm components. """
return STATUS[MY_PAGES.DEVICE_CLIMATE]
def get_smartplug_status():
""" Return a list of status overviews for alarm components. """
return STATUS[MY_PAGES.DEVICE_SMARTPLUG]
def reconnect(): def reconnect():
""" Reconnect to verisure mypages. """ """ Reconnect to verisure mypages. """
try: try:
time.sleep(1)
MY_PAGES.login() MY_PAGES.login()
except VERISURE_LOGIN_ERROR as ex: except VERISURE_LOGIN_ERROR as ex:
_LOGGER.error("Could not login to Verisure mypages, %s", ex) _LOGGER.error("Could not login to Verisure mypages, %s", ex)
@ -129,19 +117,28 @@ def reconnect():
@Throttle(MIN_TIME_BETWEEN_REQUESTS) @Throttle(MIN_TIME_BETWEEN_REQUESTS)
def update(): def update_alarm():
update_component(MY_PAGES.alarm.get, ALARM_STATUS)
@Throttle(MIN_TIME_BETWEEN_REQUESTS)
def update_climate():
update_component(MY_PAGES.climate.get, CLIMATE_STATUS)
@Throttle(MIN_TIME_BETWEEN_REQUESTS)
def update_smartplug():
update_component(MY_PAGES.smartplug.get, SMARTPLUG_STATUS)
def update_component(get_function, status):
""" Updates the status of verisure components. """ """ Updates the status of verisure components. """
if WRONG_PASSWORD_GIVEN: if WRONG_PASSWORD_GIVEN:
_LOGGER.error('Wrong password') _LOGGER.error('Wrong password')
return return
try: try:
for overview in MY_PAGES.get_overview(MY_PAGES.DEVICE_ALARM): for overview in get_function():
STATUS[MY_PAGES.DEVICE_ALARM][overview.id] = overview status[overview.id] = overview
for overview in MY_PAGES.get_overview(MY_PAGES.DEVICE_CLIMATE): except (ConnectionError, VERISURE_ERROR) as ex:
STATUS[MY_PAGES.DEVICE_CLIMATE][overview.id] = overview
for overview in MY_PAGES.get_overview(MY_PAGES.DEVICE_SMARTPLUG):
STATUS[MY_PAGES.DEVICE_SMARTPLUG][overview.id] = overview
except ConnectionError as ex:
_LOGGER.error('Caught connection error %s, tries to reconnect', ex) _LOGGER.error('Caught connection error %s, tries to reconnect', ex)
reconnect() reconnect()

View File

@ -185,7 +185,7 @@ python-nest==2.6.0
radiotherm==1.2 radiotherm==1.2
# homeassistant.components.verisure # homeassistant.components.verisure
https://github.com/persandstrom/python-verisure/archive/9873c4527f01b1ba1f72ae60f7f35854390d59be.zip#python-verisure==0.2.6 https://github.com/persandstrom/python-verisure/archive/0f53c1d6a9e370566a78e36093b02fbd5144b75d.zip#python-verisure==0.4.1
# homeassistant.components.zwave # homeassistant.components.zwave
pydispatcher==2.0.5 pydispatcher==2.0.5