Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Device and Integration Services to ISY994 #35467

Merged
merged 9 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions homeassistant/components/isy994/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
UNDO_UPDATE_LISTENER,
)
from .helpers import _categorize_nodes, _categorize_programs, _categorize_variables
from .services import async_setup_services, async_unload_services

CONFIG_SCHEMA = vol.Schema(
{
Expand Down Expand Up @@ -189,6 +190,9 @@ def _start_auto_update() -> None:

hass_isy_data[UNDO_UPDATE_LISTENER] = undo_listener

# Register Integration-wide Services:
async_setup_services(hass)

return True


Expand Down Expand Up @@ -263,4 +267,6 @@ def _stop_auto_update() -> None:
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)

async_unload_services(hass)

return unload_ok
2 changes: 2 additions & 0 deletions homeassistant/components/isy994/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
)
from .entity import ISYNodeEntity, ISYProgramEntity
from .helpers import migrate_old_unique_ids
from .services import async_setup_device_services

DEVICE_PARENT_REQUIRED = [
DEVICE_CLASS_OPENING,
Expand Down Expand Up @@ -172,6 +173,7 @@ async def async_setup_entry(

await migrate_old_unique_ids(hass, BINARY_SENSOR, devices)
async_add_entities(devices)
async_setup_device_services(hass)


def _detect_device_type_and_class(node: Union[Group, Node]) -> (str, str):
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/isy994/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
)
from .entity import ISYNodeEntity
from .helpers import migrate_old_unique_ids
from .services import async_setup_device_services

ISY_SUPPORTED_FEATURES = (
SUPPORT_FAN_MODE | SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_TEMPERATURE_RANGE
Expand All @@ -75,6 +76,7 @@ async def async_setup_entry(

await migrate_old_unique_ids(hass, CLIMATE, entities)
async_add_entities(entities)
async_setup_device_services(hass)


def convert_isy_temp_to_hass(
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/isy994/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)
from .entity import ISYNodeEntity, ISYProgramEntity
from .helpers import migrate_old_unique_ids
from .services import async_setup_device_services


async def async_setup_entry(
Expand All @@ -35,6 +36,7 @@ async def async_setup_entry(

await migrate_old_unique_ids(hass, COVER, devices)
async_add_entities(devices)
async_setup_device_services(hass)


class ISYCoverEntity(ISYNodeEntity, CoverEntity):
Expand Down
22 changes: 21 additions & 1 deletion homeassistant/components/isy994/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import Dict

from .const import DOMAIN
from .const import _LOGGER, DOMAIN


class ISYEntity(Entity):
Expand Down Expand Up @@ -166,6 +166,26 @@ def device_state_attributes(self) -> Dict:
self._attrs.update(attr)
return self._attrs

def send_node_command(self, command):
"""Respond to an entity service command call."""
if not hasattr(self._node, command):
_LOGGER.error(
"Invalid Service Call %s for device %s.", command, self.entity_id
)
return
getattr(self._node, command)()

def send_raw_node_command(
self, command, value=None, unit_of_measurement=None, parameters=None
):
"""Respond to an entity service raw command call."""
if not hasattr(self._node, "send_cmd"):
_LOGGER.error(
"Invalid Service Call %s for device %s.", command, self.entity_id
)
return
self._node.send_cmd(command, value, unit_of_measurement, parameters)


class ISYProgramEntity(ISYEntity):
"""Representation of an ISY994 program base."""
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/isy994/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .const import _LOGGER, DOMAIN as ISY994_DOMAIN, ISY994_NODES, ISY994_PROGRAMS
from .entity import ISYNodeEntity, ISYProgramEntity
from .helpers import migrate_old_unique_ids
from .services import async_setup_device_services

VALUE_TO_STATE = {
0: SPEED_OFF,
Expand Down Expand Up @@ -48,6 +49,7 @@ async def async_setup_entry(

await migrate_old_unique_ids(hass, FAN, devices)
async_add_entities(devices)
async_setup_device_services(hass)


class ISYFanEntity(ISYNodeEntity, FanEntity):
Expand Down
11 changes: 11 additions & 0 deletions homeassistant/components/isy994/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from .entity import ISYNodeEntity
from .helpers import migrate_old_unique_ids
from .services import async_setup_device_services, async_setup_light_services

ATTR_LAST_BRIGHTNESS = "last_brightness"

Expand All @@ -41,6 +42,8 @@ async def async_setup_entry(

await migrate_old_unique_ids(hass, LIGHT, devices)
async_add_entities(devices)
async_setup_device_services(hass)
async_setup_light_services(hass)


class ISYLightEntity(ISYNodeEntity, LightEntity, RestoreEntity):
Expand Down Expand Up @@ -110,3 +113,11 @@ async def async_added_to_hass(self) -> None:
and last_state.attributes[ATTR_LAST_BRIGHTNESS]
):
self._last_brightness = last_state.attributes[ATTR_LAST_BRIGHTNESS]

def set_on_level(self, value):
"""Set the ON Level for a device."""
self._node.set_on_level(value)

def set_ramp_rate(self, value):
"""Set the Ramp Rate for a device."""
self._node.set_ramp_rate(value)
2 changes: 2 additions & 0 deletions homeassistant/components/isy994/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .const import _LOGGER, DOMAIN as ISY994_DOMAIN, ISY994_NODES, ISY994_PROGRAMS
from .entity import ISYNodeEntity, ISYProgramEntity
from .helpers import migrate_old_unique_ids
from .services import async_setup_device_services

VALUE_TO_STATE = {0: STATE_UNLOCKED, 100: STATE_LOCKED}

Expand All @@ -31,6 +32,7 @@ async def async_setup_entry(

await migrate_old_unique_ids(hass, LOCK, devices)
async_add_entities(devices)
async_setup_device_services(hass)


class ISYLockEntity(ISYNodeEntity, LockEntity):
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/isy994/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)
from .entity import ISYEntity, ISYNodeEntity
from .helpers import migrate_old_unique_ids
from .services import async_setup_device_services


async def async_setup_entry(
Expand All @@ -38,6 +39,7 @@ async def async_setup_entry(

await migrate_old_unique_ids(hass, SENSOR, devices)
async_add_entities(devices)
async_setup_device_services(hass)


class ISYSensorEntity(ISYNodeEntity):
Expand Down
Loading