commit
b10149c2a0
7 changed files with 123 additions and 57 deletions
|
@ -24,7 +24,7 @@ from homeassistant.core import callback
|
|||
from homeassistant.helpers.translation import async_get_translations
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
REQUIREMENTS = ['home-assistant-frontend==20181211.1']
|
||||
REQUIREMENTS = ['home-assistant-frontend==20181211.2']
|
||||
|
||||
DOMAIN = 'frontend'
|
||||
DEPENDENCIES = ['api', 'websocket_api', 'http', 'system_log',
|
||||
|
|
|
@ -18,8 +18,8 @@ from homeassistant.components.ihc.const import (
|
|||
SERVICE_SET_RUNTIME_VALUE_FLOAT, SERVICE_SET_RUNTIME_VALUE_INT)
|
||||
from homeassistant.config import load_yaml_config_file
|
||||
from homeassistant.const import (
|
||||
CONF_BINARY_SENSORS, CONF_ID, CONF_LIGHTS, CONF_NAME, CONF_PASSWORD,
|
||||
CONF_SENSORS, CONF_SWITCHES, CONF_TYPE, CONF_UNIT_OF_MEASUREMENT, CONF_URL,
|
||||
CONF_ID, CONF_NAME, CONF_PASSWORD,
|
||||
CONF_TYPE, CONF_UNIT_OF_MEASUREMENT, CONF_URL,
|
||||
CONF_USERNAME, TEMP_CELSIUS)
|
||||
from homeassistant.helpers import discovery
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -49,7 +49,7 @@ DEVICE_SCHEMA = vol.Schema({
|
|||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Optional(CONF_POSITION): cv.string,
|
||||
vol.Optional(CONF_NOTE): cv.string
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
})
|
||||
|
||||
|
||||
SWITCH_SCHEMA = DEVICE_SCHEMA.extend({
|
||||
|
@ -75,31 +75,31 @@ IHC_SCHEMA = vol.Schema({
|
|||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_AUTOSETUP, default=True): cv.boolean,
|
||||
vol.Optional(CONF_INFO, default=True): cv.boolean,
|
||||
vol.Optional(CONF_BINARY_SENSORS, default=[]):
|
||||
vol.Optional(CONF_BINARY_SENSOR, default=[]):
|
||||
vol.All(cv.ensure_list, [
|
||||
vol.All(
|
||||
BINARY_SENSOR_SCHEMA,
|
||||
validate_name)
|
||||
]),
|
||||
vol.Optional(CONF_LIGHTS, default=[]):
|
||||
vol.Optional(CONF_LIGHT, default=[]):
|
||||
vol.All(cv.ensure_list, [
|
||||
vol.All(
|
||||
LIGHT_SCHEMA,
|
||||
validate_name)
|
||||
]),
|
||||
vol.Optional(CONF_SENSORS, default=[]):
|
||||
vol.Optional(CONF_SENSOR, default=[]):
|
||||
vol.All(cv.ensure_list, [
|
||||
vol.All(
|
||||
SENSOR_SCHEMA,
|
||||
validate_name)
|
||||
]),
|
||||
vol.Optional(CONF_SWITCHES, default=[]):
|
||||
vol.Optional(CONF_SWITCH, default=[]):
|
||||
vol.All(cv.ensure_list, [
|
||||
vol.All(
|
||||
SWITCH_SCHEMA,
|
||||
validate_name)
|
||||
]),
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
})
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema(vol.All(
|
||||
|
@ -224,7 +224,8 @@ def get_manual_configuration(hass, config, conf, ihc_controller,
|
|||
'type': sensor_cfg.get(CONF_TYPE),
|
||||
'inverting': sensor_cfg.get(CONF_INVERTING),
|
||||
'dimmable': sensor_cfg.get(CONF_DIMMABLE),
|
||||
'unit': sensor_cfg.get(CONF_UNIT_OF_MEASUREMENT)
|
||||
'unit_of_measurement': sensor_cfg.get(
|
||||
CONF_UNIT_OF_MEASUREMENT)
|
||||
}
|
||||
}
|
||||
discovery_info[name] = device
|
||||
|
|
|
@ -4,8 +4,11 @@ Support for Harmony Hub devices.
|
|||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/remote.harmony/
|
||||
"""
|
||||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
from datetime import timedelta
|
||||
from pathlib import Path
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -19,11 +22,17 @@ import homeassistant.helpers.config_validation as cv
|
|||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.util import slugify
|
||||
|
||||
REQUIREMENTS = ['pyharmony==1.0.20']
|
||||
# REQUIREMENTS = ['pyharmony==1.0.22']
|
||||
REQUIREMENTS = [
|
||||
'https://github.com/home-assistant//pyharmony/archive/'
|
||||
'4b27f8a35ea61123ef531ad078a4357cc26b00db.zip'
|
||||
'#pyharmony==1.0.21b0'
|
||||
]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_PORT = 5222
|
||||
DEFAULT_PORT = 8088
|
||||
SCAN_INTERVAL = timedelta(seconds=5)
|
||||
DEVICES = []
|
||||
CONF_DEVICE_CACHE = 'harmony_device_cache'
|
||||
|
||||
|
@ -43,7 +52,8 @@ HARMONY_SYNC_SCHEMA = vol.Schema({
|
|||
})
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the Harmony platform."""
|
||||
host = None
|
||||
activity = None
|
||||
|
@ -95,7 +105,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
device = HarmonyRemote(
|
||||
name, address, port, activity, harmony_conf_file, delay_secs)
|
||||
DEVICES.append(device)
|
||||
add_entities([device])
|
||||
async_add_entities([device])
|
||||
register_services(hass)
|
||||
except (ValueError, AttributeError):
|
||||
raise PlatformNotReady
|
||||
|
@ -103,12 +113,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
|
||||
def register_services(hass):
|
||||
"""Register all services for harmony devices."""
|
||||
hass.services.register(
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_SYNC, _sync_service,
|
||||
schema=HARMONY_SYNC_SCHEMA)
|
||||
|
||||
|
||||
def _apply_service(service, service_func, *service_func_args):
|
||||
async def _apply_service(service, service_func, *service_func_args):
|
||||
"""Handle services to apply."""
|
||||
entity_ids = service.data.get('entity_id')
|
||||
|
||||
|
@ -119,12 +129,12 @@ def _apply_service(service, service_func, *service_func_args):
|
|||
_devices = DEVICES
|
||||
|
||||
for device in _devices:
|
||||
service_func(device, *service_func_args)
|
||||
await service_func(device, *service_func_args)
|
||||
device.schedule_update_ha_state(True)
|
||||
|
||||
|
||||
def _sync_service(service):
|
||||
_apply_service(service, HarmonyRemote.sync)
|
||||
async def _sync_service(service):
|
||||
await _apply_service(service, HarmonyRemote.sync)
|
||||
|
||||
|
||||
class HarmonyRemote(remote.RemoteDevice):
|
||||
|
@ -132,8 +142,7 @@ class HarmonyRemote(remote.RemoteDevice):
|
|||
|
||||
def __init__(self, name, host, port, activity, out_path, delay_secs):
|
||||
"""Initialize HarmonyRemote class."""
|
||||
import pyharmony
|
||||
from pathlib import Path
|
||||
import pyharmony.client as harmony_client
|
||||
|
||||
_LOGGER.debug("HarmonyRemote device init started for: %s", name)
|
||||
self._name = name
|
||||
|
@ -142,23 +151,30 @@ class HarmonyRemote(remote.RemoteDevice):
|
|||
self._state = None
|
||||
self._current_activity = None
|
||||
self._default_activity = activity
|
||||
self._client = pyharmony.get_client(host, port, self.new_activity)
|
||||
# self._client = pyharmony.get_client(host, port, self.new_activity)
|
||||
self._client = harmony_client.HarmonyClient(host)
|
||||
self._config_path = out_path
|
||||
self._config = self._client.get_config()
|
||||
if not Path(self._config_path).is_file():
|
||||
_LOGGER.debug("Writing harmony configuration to file: %s",
|
||||
out_path)
|
||||
pyharmony.ha_write_config_file(self._config, self._config_path)
|
||||
self._delay_secs = delay_secs
|
||||
_LOGGER.debug("HarmonyRemote device init completed for: %s", name)
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Complete the initialization."""
|
||||
self.hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
lambda event: self._client.disconnect(wait=True))
|
||||
_LOGGER.debug("HarmonyRemote added for: %s", self._name)
|
||||
|
||||
async def shutdown(event):
|
||||
"""Close connection on shutdown."""
|
||||
await self._client.disconnect()
|
||||
|
||||
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, shutdown)
|
||||
|
||||
_LOGGER.debug("Connecting.")
|
||||
await self._client.connect()
|
||||
await self._client.get_config()
|
||||
if not Path(self._config_path).is_file():
|
||||
self.write_config_file()
|
||||
|
||||
# Poll for initial state
|
||||
self.new_activity(self._client.get_current_activity())
|
||||
self.new_activity(await self._client.get_current_activity())
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -168,7 +184,7 @@ class HarmonyRemote(remote.RemoteDevice):
|
|||
@property
|
||||
def should_poll(self):
|
||||
"""Return the fact that we should not be polled."""
|
||||
return False
|
||||
return True
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
|
@ -180,52 +196,101 @@ class HarmonyRemote(remote.RemoteDevice):
|
|||
"""Return False if PowerOff is the current activity, otherwise True."""
|
||||
return self._current_activity not in [None, 'PowerOff']
|
||||
|
||||
async def async_update(self):
|
||||
"""Retrieve current activity from Hub."""
|
||||
_LOGGER.debug("Updating Harmony.")
|
||||
if not self._client.config:
|
||||
await self._client.get_config()
|
||||
|
||||
activity_id = await self._client.get_current_activity()
|
||||
activity_name = self._client.get_activity_name(activity_id)
|
||||
_LOGGER.debug("%s activity reported as: %s", self._name, activity_name)
|
||||
self._current_activity = activity_name
|
||||
self._state = bool(self._current_activity != 'PowerOff')
|
||||
return
|
||||
|
||||
def new_activity(self, activity_id):
|
||||
"""Call for updating the current activity."""
|
||||
import pyharmony
|
||||
activity_name = pyharmony.activity_name(self._config, activity_id)
|
||||
activity_name = self._client.get_activity_name(activity_id)
|
||||
_LOGGER.debug("%s activity reported as: %s", self._name, activity_name)
|
||||
self._current_activity = activity_name
|
||||
self._state = bool(self._current_activity != 'PowerOff')
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Start an activity from the Harmony device."""
|
||||
import pyharmony
|
||||
activity = kwargs.get(ATTR_ACTIVITY, self._default_activity)
|
||||
|
||||
if activity:
|
||||
activity_id = pyharmony.activity_id(self._config, activity)
|
||||
self._client.start_activity(activity_id)
|
||||
activity_id = None
|
||||
if activity.isdigit() or activity == '-1':
|
||||
_LOGGER.debug("Activity is numeric")
|
||||
if self._client.get_activity_name(int(activity)):
|
||||
activity_id = activity
|
||||
|
||||
if not activity_id:
|
||||
_LOGGER.debug("Find activity ID based on name")
|
||||
activity_id = self._client.get_activity_id(
|
||||
str(activity).strip())
|
||||
|
||||
if not activity_id:
|
||||
_LOGGER.error("Activity %s is invalid", activity)
|
||||
return
|
||||
|
||||
await self._client.start_activity(activity_id)
|
||||
self._state = True
|
||||
else:
|
||||
_LOGGER.error("No activity specified with turn_on service")
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Start the PowerOff activity."""
|
||||
self._client.power_off()
|
||||
await self._client.power_off()
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def send_command(self, commands, **kwargs):
|
||||
async def async_send_command(self, command, **kwargs):
|
||||
"""Send a list of commands to one device."""
|
||||
device = kwargs.get(ATTR_DEVICE)
|
||||
if device is None:
|
||||
_LOGGER.error("Missing required argument: device")
|
||||
return
|
||||
|
||||
device_id = None
|
||||
if device.isdigit():
|
||||
_LOGGER.debug("Device is numeric")
|
||||
if self._client.get_device_name(int(device)):
|
||||
device_id = device
|
||||
|
||||
if not device_id:
|
||||
_LOGGER.debug("Find device ID based on device name")
|
||||
device_id = self._client.get_activity_id(str(device).strip())
|
||||
|
||||
if not device_id:
|
||||
_LOGGER.error("Device %s is invalid", device)
|
||||
return
|
||||
|
||||
num_repeats = kwargs.get(ATTR_NUM_REPEATS)
|
||||
delay_secs = kwargs.get(ATTR_DELAY_SECS, self._delay_secs)
|
||||
|
||||
for _ in range(num_repeats):
|
||||
for command in commands:
|
||||
self._client.send_command(device, command)
|
||||
time.sleep(delay_secs)
|
||||
for single_command in command:
|
||||
_LOGGER.debug("Sending command %s", single_command)
|
||||
await self._client.send_command(device, single_command)
|
||||
await asyncio.sleep(delay_secs)
|
||||
|
||||
def sync(self):
|
||||
async def sync(self):
|
||||
"""Sync the Harmony device with the web service."""
|
||||
import pyharmony
|
||||
_LOGGER.debug("Syncing hub with Harmony servers")
|
||||
self._client.sync()
|
||||
self._config = self._client.get_config()
|
||||
await self._client.sync()
|
||||
await self._client.get_config()
|
||||
await self.hass.async_add_executor_job(self.write_config_file)
|
||||
|
||||
def write_config_file(self):
|
||||
"""Write Harmony configuration file."""
|
||||
_LOGGER.debug("Writing hub config to file: %s", self._config_path)
|
||||
pyharmony.ha_write_config_file(self._config, self._config_path)
|
||||
try:
|
||||
with open(self._config_path, 'w+', encoding='utf-8') as file_out:
|
||||
json.dump(self._client.json_config, file_out,
|
||||
sort_keys=True, indent=4)
|
||||
except IOError as exc:
|
||||
_LOGGER.error("Unable to write HUB configuration to %s: %s",
|
||||
self._config_path, exc)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"""Constants used by Home Assistant components."""
|
||||
MAJOR_VERSION = 0
|
||||
MINOR_VERSION = 84
|
||||
PATCH_VERSION = '3'
|
||||
PATCH_VERSION = '4'
|
||||
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
|
||||
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
|
||||
REQUIRED_PYTHON_VER = (3, 5, 3)
|
||||
|
|
|
@ -493,7 +493,7 @@ hole==0.3.0
|
|||
holidays==0.9.8
|
||||
|
||||
# homeassistant.components.frontend
|
||||
home-assistant-frontend==20181211.1
|
||||
home-assistant-frontend==20181211.2
|
||||
|
||||
# homeassistant.components.zwave
|
||||
homeassistant-pyozw==0.1.1
|
||||
|
@ -508,6 +508,9 @@ homematicip==0.9.8
|
|||
# homeassistant.components.remember_the_milk
|
||||
httplib2==0.10.3
|
||||
|
||||
# homeassistant.components.remote.harmony
|
||||
https://github.com/home-assistant//pyharmony/archive/4b27f8a35ea61123ef531ad078a4357cc26b00db.zip#pyharmony==1.0.21b0
|
||||
|
||||
# homeassistant.components.huawei_lte
|
||||
huawei-lte-api==1.0.16
|
||||
|
||||
|
@ -965,9 +968,6 @@ pygogogate2==0.1.1
|
|||
# homeassistant.components.sensor.gtfs
|
||||
pygtfs-homeassistant==0.1.3.dev0
|
||||
|
||||
# homeassistant.components.remote.harmony
|
||||
pyharmony==1.0.20
|
||||
|
||||
# homeassistant.components.sensor.version
|
||||
pyhaversion==2.0.3
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ hdate==0.7.5
|
|||
holidays==0.9.8
|
||||
|
||||
# homeassistant.components.frontend
|
||||
home-assistant-frontend==20181211.1
|
||||
home-assistant-frontend==20181211.2
|
||||
|
||||
# homeassistant.components.homematicip_cloud
|
||||
homematicip==0.9.8
|
||||
|
|
|
@ -209,7 +209,7 @@ def gather_modules():
|
|||
for req in module.REQUIREMENTS:
|
||||
if req in IGNORE_REQ:
|
||||
continue
|
||||
if '://' in req:
|
||||
if '://' in req and 'pyharmony' not in req:
|
||||
errors.append(
|
||||
"{}[Only pypi dependencies are allowed: {}]".format(
|
||||
package, req))
|
||||
|
|
Loading…
Add table
Reference in a new issue