Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiH committed Jan 16, 2024
1 parent c142a5d commit 1525810
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions TheengsGateway/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1525810

Please sign in to comment.