Replies: 2 comments
-
To answer my own question; I believe that the tuple field access is for this: https://smarthomeconnect.readthedocs.io/en/latest/variables_expressions.html#tuple-field-access |
Beta Was this translation helpful? Give feedback.
-
Thanks for checking out SHC and for your question! 🙂 So, if I understand correctly, you want to keep multiple properties of a single light in a single Variable. That's not strictly necessary; in my personal SHC projects, I just created multiple Variables for lights which have an on/off value and e.g. a dimmer percentage value. If you still want to do that, you're right with your own answer: You can create a typed NamedTuple and use it as the Variable's value type. Than you can use the import typing
import shc
import shc.web
import shc.web.widgets
class MySpecialLightbulb(typing.NamedTuple):
on_off: bool
brightness: shc.datatypes.RangeFloat1
color: shc.datatypes.RGBUInt8
light_state = shc.Variable(MySpecialLightbulb, "light_state")\
.connect(my_special_light_interface.light_state_connector()) # or however you get the connectable object for your light
web_server = shc.web.WebServer('localhost', 8080, index_name='index')
page = web_server.page('index', 'Home')
page.add_item(shc.web.widgets.Switch("My light", color="yellow")
.connect(light_state.field("on_off"))) The interesting bit w.r.t. to your question is the last line of that snippet: There, the Note, that in this configuration, upon every change of the Further note, that this will only work, once the Variable itself is initialized with a complete |
Beta Was this translation helpful? Give feedback.
-
I'm trying to do the following:
light_state
light_state
variablelight_state
variable (to actually turn the light on or off)The last step needs the entire light_state to work.
In my attempt I created an extra bool variable
light_on
that is connected with thelight_state
and can be shown as a switch. However I'm not sure how to update thelight_state
when thelight_on
gets updated.Beta Was this translation helpful? Give feedback.
All reactions