Skip to content

Commit

Permalink
Merge pull request #379 from automicus:fix_variables
Browse files Browse the repository at this point in the history
Revise variable value setting to use expected types
  • Loading branch information
shbatm authored Jan 30, 2023
2 parents 567695e + 6779b54 commit 56d21cb
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions pyisy/variables/variable.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Manage variables from the ISY."""
from __future__ import annotations

from ..constants import (
ATTR_INIT,
ATTR_LAST_CHANGED,
Expand Down Expand Up @@ -173,31 +175,29 @@ async def update(self, wait_time=0):
self._last_update = now()
await self._variables.update(wait_time)

async def set_init(self, val):
async def set_init(self, value: int | float) -> bool:
"""
Set the initial value for the variable after the controller boots.
| val: The value to have the variable initialize to.
"""
if val is None:
raise ValueError("Variable init must be an integer. Got None.")
self.set_value(val, True)
return await self.set_value(value, True)

async def set_value(self, val, init=False):
async def set_value(self, value: int | float, init: bool = False) -> bool:
"""
Set the value of the variable.
| val: The value to set the variable to.
ISY Version 5 firmware will automatically convert float back to int.
"""
if val is None:
raise ValueError("Variable value must be an integer. Got None.")
req_url = self.isy.conn.compile_url(
[
URL_VARIABLES,
ATTR_INIT if init else ATTR_SET,
str(self._type),
str(self._id),
str(val),
str(value),
]
)
if not await self.isy.conn.request(req_url):
Expand All @@ -207,12 +207,11 @@ async def set_value(self, val, init=False):
str(self._type),
str(self._id),
)
return
return False
_LOGGER.debug(
"ISY set variable%s: %s.%s",
" init value" if init else "",
str(self._type),
str(self._id),
)
if not self.isy.auto_update:
await self.update()
return True

0 comments on commit 56d21cb

Please sign in to comment.