diff --git a/TheengsGateway/discovery.py b/TheengsGateway/discovery.py index aedacc33..0e1f7c4d 100644 --- a/TheengsGateway/discovery.py +++ b/TheengsGateway/discovery.py @@ -164,7 +164,12 @@ def publish_device_info(self, pub_device) -> None: # noqa: ANN001 device["pl_off"] = "False" device["name"] = pub_device["model_id"] + "-" + k device["uniq_id"] = pub_device_uuid + "-" + k - device["val_tpl"] = self.get_val_tpl(k) + if k == "unlocked": + device["val_tpl"] = "{% if value_json.get('unlocked') is true -%}True{%- else -%}False{%- endif %}" # noqa: E501 + elif self.configuration["hass_discovery"]: + device["val_tpl"] = "{{ value_json." + k + " | is_defined }}" + else: + device["val_tpl"] = "{{ value_json." + k + " }}" config_topic = ( discovery_topic @@ -198,17 +203,6 @@ def publish_device_data(self, uuid: str, data: str) -> None: if self.configuration["presence"]: self.publish(data, self.configuration["presence_topic"]) - def get_val_tpl(self, k: str) -> str: - """Get value_template.""" - if k == "unlocked": - val_tpl = "{% if value_json.get('unlocked') is true -%}True{%- else -%}False{%- endif %}" # noqa: E501 - elif self.configuration["hass_discovery"]: - val_tpl = "{{ value_json." + k + " | is_defined }}" - else: - val_tpl = "{{ value_json." + k + " }}" - - return val_tpl - def prepare_hadevice(self, uuid: str, device: dict) -> dict: """Prepare Home Assistant device configuration.""" return {