Skip to content

Commit

Permalink
Allow dial to be None (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt authored Dec 5, 2024
1 parent 1507f57 commit c5fa9ba
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions home_assistant_streamdeck_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,9 +1547,10 @@ def _round(num: float, digits: int) -> int | float:
return round(num, digits)


def _dial_value(dial: Dial) -> float:
def _dial_value(dial: Dial | None) -> float:
if dial is None:
return 0
try:
assert dial is not None
attributes = dial.get_attributes()
return float(attributes["state"])
except KeyError:
Expand All @@ -1558,8 +1559,10 @@ def _dial_value(dial: Dial) -> float:

def _dial_attr(
attr: str,
dial: Dial,
dial: Dial | None,
) -> float:
if dial is None:
return 0
try:
assert attr is not None
dial_attributes = dial.get_attributes()
Expand Down Expand Up @@ -1589,7 +1592,6 @@ def _render_jinja(
env.filters["min"] = _min_filter
env.filters["max"] = _max_filter
template = env.from_string(text)
assert dial is not None
return template.render(
min=min,
max=max,
Expand Down

0 comments on commit c5fa9ba

Please sign in to comment.