Skip to content

Commit 0ef374d

Browse files
committed
renamed StateVar to StateVal, since it's a static value, not the current one
1 parent 803bcca commit 0ef374d

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

custom_components/pyscript/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from .global_ctx import GlobalContext, GlobalContextMgr
3737
from .jupyter_kernel import Kernel
3838
from .requirements import install_requirements
39-
from .state import State, StateVar
39+
from .state import State, StateVal
4040
from .trigger import TrigTime
4141

4242
_LOGGER = logging.getLogger(LOGGER_PATH)
@@ -189,13 +189,13 @@ def state_var_remove():
189189
async def state_changed(event):
190190
var_name = event.data["entity_id"]
191191
if event.data.get("new_state", None):
192-
new_val = StateVar(event.data["new_state"])
192+
new_val = StateVal(event.data["new_state"])
193193
else:
194194
# state variable has been deleted
195195
new_val = None
196196

197197
if event.data.get("old_state", None):
198-
old_val = StateVar(event.data["old_state"])
198+
old_val = StateVal(event.data["old_state"])
199199
else:
200200
# no previous state
201201
old_val = None

custom_components/pyscript/state.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
STATE_VIRTUAL_ATTRS = {"last_changed", "last_updated"}
1616

1717

18-
class StateVar(str):
18+
class StateVal(str):
1919
"""Class for representing the value and attributes of a state variable."""
2020

2121
def __new__(cls, state):
@@ -152,10 +152,10 @@ async def set(cls, var_name, value=None, new_attributes=None, **kwargs):
152152
if var_name.count(".") != 1:
153153
raise NameError(f"invalid name {var_name} (should be 'domain.entity')")
154154

155-
if isinstance(value, StateVar):
155+
if isinstance(value, StateVal):
156156
if new_attributes is None:
157157
#
158-
# value is a StateVar, so extract the attributes and value
158+
# value is a StateVal, so extract the attributes and value
159159
#
160160
new_attributes = value.__dict__.copy()
161161
for discard in STATE_VIRTUAL_ATTRS:
@@ -193,7 +193,7 @@ async def set(cls, var_name, value=None, new_attributes=None, **kwargs):
193193
# immediately update a variable we are monitoring since it could take a while
194194
# for the state changed event to propagate
195195
#
196-
cls.notify_var_last[var_name] = StateVar(cls.hass.states.get(var_name))
196+
cls.notify_var_last[var_name] = StateVal(cls.hass.states.get(var_name))
197197

198198
@classmethod
199199
async def setattr(cls, var_attr_name, value):
@@ -259,7 +259,7 @@ async def get(cls, var_name):
259259
#
260260
# simplest case is just the state value
261261
#
262-
state = StateVar(state)
262+
state = StateVal(state)
263263
if len(parts) == 2:
264264
return state
265265
#

tests/test_decorator_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def func_wrapup():
194194
"""Exception in <file.hello.func6 @state_active()> line 1:
195195
1 / pyscript.var1
196196
^
197-
TypeError: unsupported operand type(s) for /: 'int' and 'StateVar'"""
197+
TypeError: unsupported operand type(s) for /: 'int' and 'StateVal'"""
198198
in caplog.text
199199
)
200200

0 commit comments

Comments
 (0)