From ccc1bb4f308522f4e638b543c84c9d59c7273d08 Mon Sep 17 00:00:00 2001 From: brefra Date: Sat, 25 Jan 2020 20:35:36 +0100 Subject: [PATCH 1/5] Add set_memo_text service --- homeassistant/components/velbus/__init__.py | 25 ++++++++++++++++++- homeassistant/components/velbus/const.py | 3 +++ homeassistant/components/velbus/services.yaml | 16 ++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/velbus/__init__.py b/homeassistant/components/velbus/__init__.py index b4fe49a88e7b3..c8bec5f682f83 100644 --- a/homeassistant/components/velbus/__init__.py +++ b/homeassistant/components/velbus/__init__.py @@ -12,7 +12,7 @@ from homeassistant.helpers.entity import Entity from homeassistant.helpers.typing import HomeAssistantType -from .const import DOMAIN +from .const import ATTR_MEMO_TEXT, ATTR_MODULE_ADDRESS, DOMAIN _LOGGER = logging.getLogger(__name__) @@ -80,6 +80,29 @@ def syn_clock(self, service=None): hass.services.async_register(DOMAIN, "sync_clock", syn_clock, schema=vol.Schema({})) + def set_memo_text(service): + """Handle Memo Text service call.""" + try: + controller.get_module(service.data[ATTR_MODULE_ADDRESS]).set_memo_text( + service.data[ATTR_MEMO_TEXT] + ) + except velbus.util.VelbusException as err: + _LOGGER.error("An error occurred: %s", err) + + hass.services.async_register( + DOMAIN, + "set_memo_text", + set_memo_text, + vol.Schema( + { + vol.Required(ATTR_MODULE_ADDRESS): vol.All( + vol.Coerce(int), vol.Range(min=0, max=255) + ), + vol.Optional(ATTR_MEMO_TEXT, default=""): cv.string, + } + ), + ) + return True diff --git a/homeassistant/components/velbus/const.py b/homeassistant/components/velbus/const.py index 0d3a66fa74354..9df8bfef7c0dc 100644 --- a/homeassistant/components/velbus/const.py +++ b/homeassistant/components/velbus/const.py @@ -1,3 +1,6 @@ """Const for Velbus.""" +ATTR_MEMO_TEXT = "memo_text" +ATTR_MODULE_ADDRESS = "address" + DOMAIN = "velbus" diff --git a/homeassistant/components/velbus/services.yaml b/homeassistant/components/velbus/services.yaml index 273cc8b4caa85..ea31b951a188f 100644 --- a/homeassistant/components/velbus/services.yaml +++ b/homeassistant/components/velbus/services.yaml @@ -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' \ No newline at end of file From c2003293bc539fc7adb5b6945d7500ffe6e7a9dd Mon Sep 17 00:00:00 2001 From: brefra Date: Sat, 1 Feb 2020 17:21:12 +0100 Subject: [PATCH 2/5] Apply template rendering for memo text --- homeassistant/components/velbus/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/velbus/__init__.py b/homeassistant/components/velbus/__init__.py index c8bec5f682f83..356ebac639d16 100644 --- a/homeassistant/components/velbus/__init__.py +++ b/homeassistant/components/velbus/__init__.py @@ -82,9 +82,11 @@ def syn_clock(self, service=None): def set_memo_text(service): """Handle Memo Text service call.""" + memo_text = service.data[ATTR_MEMO_TEXT] + memo_text.hass = hass try: controller.get_module(service.data[ATTR_MODULE_ADDRESS]).set_memo_text( - service.data[ATTR_MEMO_TEXT] + memo_text.async_render() ) except velbus.util.VelbusException as err: _LOGGER.error("An error occurred: %s", err) @@ -98,7 +100,7 @@ def set_memo_text(service): vol.Required(ATTR_MODULE_ADDRESS): vol.All( vol.Coerce(int), vol.Range(min=0, max=255) ), - vol.Optional(ATTR_MEMO_TEXT, default=""): cv.string, + vol.Optional(ATTR_MEMO_TEXT, default=""): cv.template, } ), ) From aa7594916cc5f01452dde4fc72971c0b8bb2a2d8 Mon Sep 17 00:00:00 2001 From: brefra Date: Sun, 8 Mar 2020 21:10:16 +0100 Subject: [PATCH 3/5] Update constants to comply to naming conventions --- homeassistant/components/velbus/__init__.py | 14 +++++++------- homeassistant/components/velbus/const.py | 7 ++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/velbus/__init__.py b/homeassistant/components/velbus/__init__.py index 356ebac639d16..47041a9292e07 100644 --- a/homeassistant/components/velbus/__init__.py +++ b/homeassistant/components/velbus/__init__.py @@ -6,13 +6,13 @@ 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 ATTR_MEMO_TEXT, ATTR_MODULE_ADDRESS, DOMAIN +from .const import CONF_MEMO_TEXT, DOMAIN, SERVICE_SET_MEMO_TEXT _LOGGER = logging.getLogger(__name__) @@ -82,10 +82,10 @@ def syn_clock(self, service=None): def set_memo_text(service): """Handle Memo Text service call.""" - memo_text = service.data[ATTR_MEMO_TEXT] + memo_text = service.data[CONF_MEMO_TEXT] memo_text.hass = hass try: - controller.get_module(service.data[ATTR_MODULE_ADDRESS]).set_memo_text( + controller.get_module(service.data[CONF_ADDRESS]).set_memo_text( memo_text.async_render() ) except velbus.util.VelbusException as err: @@ -93,14 +93,14 @@ def set_memo_text(service): hass.services.async_register( DOMAIN, - "set_memo_text", + SERVICE_SET_MEMO_TEXT, set_memo_text, vol.Schema( { - vol.Required(ATTR_MODULE_ADDRESS): vol.All( + vol.Required(CONF_ADDRESS): vol.All( vol.Coerce(int), vol.Range(min=0, max=255) ), - vol.Optional(ATTR_MEMO_TEXT, default=""): cv.template, + vol.Optional(CONF_MEMO_TEXT, default=""): cv.template, } ), ) diff --git a/homeassistant/components/velbus/const.py b/homeassistant/components/velbus/const.py index 9df8bfef7c0dc..d3987295fce30 100644 --- a/homeassistant/components/velbus/const.py +++ b/homeassistant/components/velbus/const.py @@ -1,6 +1,7 @@ """Const for Velbus.""" -ATTR_MEMO_TEXT = "memo_text" -ATTR_MODULE_ADDRESS = "address" - DOMAIN = "velbus" + +CONF_MEMO_TEXT = "memo_text" + +SERVICE_SET_MEMO_TEXT = "set_memo_text" From 149f0c7e8216d420fa1a3687ed127e3506a3e267 Mon Sep 17 00:00:00 2001 From: brefra Date: Wed, 11 Mar 2020 19:24:12 +0100 Subject: [PATCH 4/5] Local variable for module address and extended error description --- homeassistant/components/velbus/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/velbus/__init__.py b/homeassistant/components/velbus/__init__.py index 47041a9292e07..4ad684c4a5ac4 100644 --- a/homeassistant/components/velbus/__init__.py +++ b/homeassistant/components/velbus/__init__.py @@ -82,14 +82,15 @@ def syn_clock(self, service=None): 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(service.data[CONF_ADDRESS]).set_memo_text( + controller.get_module(module_address).set_memo_text( memo_text.async_render() ) except velbus.util.VelbusException as err: - _LOGGER.error("An error occurred: %s", err) + _LOGGER.error("An error occurred while setting memo text: %s", err) hass.services.async_register( DOMAIN, From b1ef3fcd4843db83a07dbdec0058e7681a2170de Mon Sep 17 00:00:00 2001 From: brefra Date: Wed, 11 Mar 2020 19:27:57 +0100 Subject: [PATCH 5/5] fixed typo --- homeassistant/components/velbus/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/velbus/__init__.py b/homeassistant/components/velbus/__init__.py index 4ad684c4a5ac4..72ffda48b5711 100644 --- a/homeassistant/components/velbus/__init__.py +++ b/homeassistant/components/velbus/__init__.py @@ -82,7 +82,7 @@ def syn_clock(self, service=None): def set_memo_text(service): """Handle Memo Text service call.""" - module_address service.data[CONF_ADDRESS] + module_address = service.data[CONF_ADDRESS] memo_text = service.data[CONF_MEMO_TEXT] memo_text.hass = hass try: