Skip to content

Commit

Permalink
Merge 8fe524c into 4f8ae49
Browse files Browse the repository at this point in the history
  • Loading branch information
farmio committed Feb 17, 2021
2 parents 4f8ae49 + 8fe524c commit a4b1e54
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
28 changes: 27 additions & 1 deletion home-assistant-plugin/custom_components/xknx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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_HOST,
Expand Down Expand Up @@ -68,6 +68,7 @@
SERVICE_XKNX_ATTR_REMOVE = "remove"
SERVICE_XKNX_EVENT_REGISTER = "event_register"
SERVICE_XKNX_EXPOSURE_REGISTER = "exposure_register"
SERVICE_XKNX_READ = "read"

CONFIG_SCHEMA = vol.Schema(
{
Expand Down Expand Up @@ -156,6 +157,15 @@
),
)

SERVICE_XKNX_READ_SCHEMA = vol.Schema(
{
vol.Required(SERVICE_XKNX_ATTR_ADDRESS): vol.All(
cv.ensure_list,
[cv.string],
)
}
)

SERVICE_XKNX_EVENT_REGISTER_SCHEMA = vol.Schema(
{
vol.Required(SERVICE_XKNX_ATTR_ADDRESS): cv.string,
Expand Down Expand Up @@ -221,6 +231,13 @@ async def async_setup(hass, config):
schema=SERVICE_XKNX_SEND_SCHEMA,
)

hass.services.async_register(
DOMAIN,
SERVICE_XKNX_READ,
hass.data[DOMAIN].service_read_to_knx_bus,
schema=SERVICE_XKNX_READ_SCHEMA,
)

async_register_admin_service(
hass,
DOMAIN,
Expand Down Expand Up @@ -443,3 +460,12 @@ def calculate_payload(attr_payload):
payload=GroupValueWrite(calculate_payload(attr_payload)),
)
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_XKNX_ATTR_ADDRESS):
telegram = Telegram(
destination_address=GroupAddress(address),
payload=GroupValueRead(),
)
await self.xknx.telegrams.put(telegram)
6 changes: 6 additions & 0 deletions home-assistant-plugin/custom_components/xknx/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a4b1e54

Please sign in to comment.