knx-read-service (#46670)

pull/46830/head
Matthias Alphart 2021-02-20 20:09:23 +01:00 committed by GitHub
parent 2cf46330b1
commit 194c0d2b08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -15,7 +15,7 @@ from xknx.io import (
ConnectionType,
)
from xknx.telegram import AddressFilter, GroupAddress, Telegram
from xknx.telegram.apci import GroupValueResponse, GroupValueWrite
from xknx.telegram.apci import GroupValueRead, GroupValueResponse, GroupValueWrite
from homeassistant.const import (
CONF_ENTITY_ID,
@ -75,6 +75,7 @@ SERVICE_KNX_ATTR_PAYLOAD = "payload"
SERVICE_KNX_ATTR_TYPE = "type"
SERVICE_KNX_ATTR_REMOVE = "remove"
SERVICE_KNX_EVENT_REGISTER = "event_register"
SERVICE_KNX_READ = "read"
CONFIG_SCHEMA = vol.Schema(
{
@ -166,6 +167,15 @@ SERVICE_KNX_SEND_SCHEMA = vol.Any(
),
)
SERVICE_KNX_READ_SCHEMA = vol.Schema(
{
vol.Required(SERVICE_KNX_ATTR_ADDRESS): vol.All(
cv.ensure_list,
[cv.string],
)
}
)
SERVICE_KNX_EVENT_REGISTER_SCHEMA = vol.Schema(
{
vol.Required(SERVICE_KNX_ATTR_ADDRESS): cv.string,
@ -210,6 +220,13 @@ async def async_setup(hass, config):
schema=SERVICE_KNX_SEND_SCHEMA,
)
hass.services.async_register(
DOMAIN,
SERVICE_KNX_READ,
hass.data[DOMAIN].service_read_to_knx_bus,
schema=SERVICE_KNX_READ_SCHEMA,
)
async_register_admin_service(
hass,
DOMAIN,
@ -423,6 +440,15 @@ class KNXModule:
)
await self.xknx.telegrams.put(telegram)
async def service_read_to_knx_bus(self, call):
"""Service for sending a GroupValueRead telegram to the KNX bus."""
for address in call.data.get(SERVICE_KNX_ATTR_ADDRESS):
telegram = Telegram(
destination_address=GroupAddress(address),
payload=GroupValueRead(),
)
await self.xknx.telegrams.put(telegram)
class KNXExposeTime:
"""Object to Expose Time/Date object to KNX bus."""

View File

@ -10,6 +10,12 @@ send:
type:
description: "Optional. If set, the payload will not be sent as raw bytes, but encoded as given DPT. Knx sensor types are valid values (see https://www.home-assistant.io/integrations/sensor.knx)."
example: "temperature"
read:
description: "Send GroupValueRead requests to the KNX bus. Response can be used from `knx_event` and will be processed in KNX entities."
fields:
address:
description: "Group address(es) to send read request to. Lists will read multiple group addresses."
example: "1/1/0"
event_register:
description: "Add or remove single group address to knx_event filter for triggering `knx_event`s. Only addresses added with this service can be removed."
fields: