Skip to content

Commit

Permalink
Revise variable value setting to use expected types
Browse files Browse the repository at this point in the history
  • Loading branch information
shbatm committed Jan 30, 2023
1 parent f4f0634 commit 6779b54
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 6779b54

Please sign in to comment.