Add service to openhome to invoke a pin (#31119)
Setup platform async Use entity services Store UUID in default data rather than entity
This commit is contained in:
parent
efec62d98e
commit
b6407f77da
6 changed files with 45 additions and 12 deletions
|
@ -564,7 +564,9 @@ omit =
|
|||
homeassistant/components/openevse/sensor.py
|
||||
homeassistant/components/openexchangerates/sensor.py
|
||||
homeassistant/components/opengarage/cover.py
|
||||
homeassistant/components/openhome/__init__.py
|
||||
homeassistant/components/openhome/media_player.py
|
||||
homeassistant/components/openhome/const.py
|
||||
homeassistant/components/opensensemap/air_quality.py
|
||||
homeassistant/components/opensky/sensor.py
|
||||
homeassistant/components/opentherm_gw/__init__.py
|
||||
|
|
5
homeassistant/components/openhome/const.py
Normal file
5
homeassistant/components/openhome/const.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
"""Constants for the Openhome component."""
|
||||
DOMAIN = "openhome"
|
||||
SERVICE_INVOKE_PIN = "invoke_pin"
|
||||
ATTR_PIN_INDEX = "pin"
|
||||
DATA_OPENHOME = "openhome"
|
|
@ -2,6 +2,6 @@
|
|||
"domain": "openhome",
|
||||
"name": "Linn / OpenHome",
|
||||
"documentation": "https://www.home-assistant.io/integrations/openhome",
|
||||
"requirements": ["openhomedevice==0.6.3"],
|
||||
"requirements": ["openhomedevice==0.7.2"],
|
||||
"codeowners": []
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import logging
|
||||
|
||||
from openhomedevice.Device import Device
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.media_player import MediaPlayerEntity
|
||||
from homeassistant.components.media_player.const import (
|
||||
|
@ -20,35 +21,45 @@ from homeassistant.components.media_player.const import (
|
|||
SUPPORT_VOLUME_STEP,
|
||||
)
|
||||
from homeassistant.const import STATE_IDLE, STATE_OFF, STATE_PAUSED, STATE_PLAYING
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
|
||||
from .const import ATTR_PIN_INDEX, DATA_OPENHOME, SERVICE_INVOKE_PIN
|
||||
|
||||
SUPPORT_OPENHOME = SUPPORT_SELECT_SOURCE | SUPPORT_TURN_OFF | SUPPORT_TURN_ON
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEVICES = []
|
||||
|
||||
|
||||
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 Openhome platform."""
|
||||
|
||||
if not discovery_info:
|
||||
return True
|
||||
return
|
||||
|
||||
openhome_data = hass.data.setdefault(DATA_OPENHOME, set())
|
||||
|
||||
name = discovery_info.get("name")
|
||||
description = discovery_info.get("ssdp_description")
|
||||
|
||||
_LOGGER.info("Openhome device found: %s", name)
|
||||
device = Device(description)
|
||||
device = await hass.async_add_executor_job(Device, description)
|
||||
|
||||
# if device has already been discovered
|
||||
if device.Uuid() in [x.unique_id for x in DEVICES]:
|
||||
if device.Uuid() in openhome_data:
|
||||
return True
|
||||
|
||||
device = OpenhomeDevice(hass, device)
|
||||
entity = OpenhomeDevice(hass, device)
|
||||
|
||||
add_entities([device], True)
|
||||
DEVICES.append(device)
|
||||
async_add_entities([entity])
|
||||
openhome_data.add(device.Uuid())
|
||||
|
||||
return True
|
||||
platform = entity_platform.current_platform.get()
|
||||
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_INVOKE_PIN,
|
||||
{vol.Required(ATTR_PIN_INDEX): cv.positive_int},
|
||||
"invoke_pin",
|
||||
)
|
||||
|
||||
|
||||
class OpenhomeDevice(MediaPlayerEntity):
|
||||
|
@ -162,6 +173,10 @@ class OpenhomeDevice(MediaPlayerEntity):
|
|||
"""Select input source."""
|
||||
self._device.SetSource(self._source_index[source])
|
||||
|
||||
def invoke_pin(self, pin):
|
||||
"""Invoke pin."""
|
||||
self._device.InvokePin(pin)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
|
|
11
homeassistant/components/openhome/services.yaml
Normal file
11
homeassistant/components/openhome/services.yaml
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Describes the format for available openhome services
|
||||
|
||||
invoke_pin:
|
||||
description: Invoke a pin on the specified device.
|
||||
fields:
|
||||
entity_id:
|
||||
description: The name of the openhome device to invoke the pin on
|
||||
example: media_player.main_room
|
||||
pin:
|
||||
description: Which pin to invoke
|
||||
example: 4
|
|
@ -1012,7 +1012,7 @@ openerz-api==0.1.0
|
|||
openevsewifi==0.4
|
||||
|
||||
# homeassistant.components.openhome
|
||||
openhomedevice==0.6.3
|
||||
openhomedevice==0.7.2
|
||||
|
||||
# homeassistant.components.opensensemap
|
||||
opensensemap-api==0.1.5
|
||||
|
|
Loading…
Add table
Reference in a new issue