Add memo text service (#31222)

* Add set_memo_text service

* Apply template rendering for memo text

* Update constants to comply to naming conventions

* Local variable for module address and extended error description

* fixed typo
pull/32767/head
brefra 2020-03-13 08:09:30 +01:00 committed by GitHub
parent 7e6e36db15
commit 31d150794d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 2 deletions

View File

@ -6,13 +6,13 @@ import velbus
import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_NAME, CONF_PORT
from homeassistant.const import CONF_ADDRESS, CONF_NAME, CONF_PORT
from homeassistant.exceptions import ConfigEntryNotReady
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import HomeAssistantType
from .const import DOMAIN
from .const import CONF_MEMO_TEXT, DOMAIN, SERVICE_SET_MEMO_TEXT
_LOGGER = logging.getLogger(__name__)
@ -80,6 +80,32 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
hass.services.async_register(DOMAIN, "sync_clock", syn_clock, schema=vol.Schema({}))
def set_memo_text(service):
"""Handle Memo Text service call."""
module_address = service.data[CONF_ADDRESS]
memo_text = service.data[CONF_MEMO_TEXT]
memo_text.hass = hass
try:
controller.get_module(module_address).set_memo_text(
memo_text.async_render()
)
except velbus.util.VelbusException as err:
_LOGGER.error("An error occurred while setting memo text: %s", err)
hass.services.async_register(
DOMAIN,
SERVICE_SET_MEMO_TEXT,
set_memo_text,
vol.Schema(
{
vol.Required(CONF_ADDRESS): vol.All(
vol.Coerce(int), vol.Range(min=0, max=255)
),
vol.Optional(CONF_MEMO_TEXT, default=""): cv.template,
}
),
)
return True

View File

@ -1,3 +1,7 @@
"""Const for Velbus."""
DOMAIN = "velbus"
CONF_MEMO_TEXT = "memo_text"
SERVICE_SET_MEMO_TEXT = "set_memo_text"

View File

@ -1,2 +1,18 @@
sync_clock:
description: Sync the velbus modules clock to the Home Assistant clock, this is the same as the 'sync clock' from VelbusLink
set_memo_text:
description: >
Set the memo text to the display of modules like VMBGPO, VMBGPOD
Be sure the page(s) of the module is configured to display the memo text.
fields:
address:
description: >
The module address in decimal format.
The decimal addresses are displayed in front of the modules listed at the integration page.
example: '11'
memo_text:
description: >
The actual text to be displayed.
Text is limited to 64 characters.
example: 'Do not forget trash'