Skip to content

Commit

Permalink
Merge pull request #41 from P-Storm/feat/template
Browse files Browse the repository at this point in the history
added template support for automation
  • Loading branch information
koenhendriks authored Mar 10, 2024
2 parents 5cfb61a + eefbba8 commit 84d43d2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions custom_components/button_plus/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.components.mqtt import client as mqtt
from homeassistant.helpers import template
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from custom_components.button_plus.button_plus_api.model import Connector
Expand Down Expand Up @@ -114,11 +115,13 @@ def device_info(self):

async def async_set_value(self, value: str) -> None:
"""Set the text value and publish to mqtt."""
parse_value: Any = template.Template(value, self.hass).async_render(parse_result=False)

label_topic = f"buttonplus/{self._hub_id}/button/{self._btn_id}/{self._text_type}"
_LOGGER.debug(f"ButtonPlus label update for {self.entity_id}")
_LOGGER.debug(f"ButtonPlus label update to {label_topic} with new value: {value}")
await mqtt.async_publish(hass=self.hass, topic=label_topic, payload=value, qos=0, retain=True)
self._attr_native_value = value
_LOGGER.debug(f"ButtonPlus label update to {label_topic} with new value: {parse_value}")
await mqtt.async_publish(hass=self.hass, topic=label_topic, payload=parse_value, qos=0, retain=True)
self._attr_native_value = parse_value
self.async_write_ha_state()


Expand Down

0 comments on commit 84d43d2

Please sign in to comment.