@@ -261,9 +261,12 @@ State variables have attributes that can be accessed by adding the name of the a
261
261
them, so you will need to look at the State tab in the Developer Tools to see the available
262
262
attributes.
263
263
264
- In cases where you need to compute the name of the state variable dynamically, or you need to
265
- set the state attributes, you can use the built-in functions `state.get(name)` and
266
- ` state.set(name, value, attr=None)` ; see below.
264
+ Starting in version 0.21, when you set a state variable, the existing attributes are not
265
+ affected (they were previously removed).
266
+
267
+ In cases where you need to compute the name of the state variable dynamically, or you need
268
+ to set or get the state attributes, you can use the built-in functions `state.get()`,
269
+ ` state.get_attr()` and `state.set()`; see below.
267
270
268
271
The function `state.names(domain=None)` returns a list of all state variable names (ie, `entity_id`s)
269
272
of a domain. If `domain` is not specified, it returns all HASS state variable (entity) names.
@@ -582,14 +585,23 @@ set the attributes, which you can't do if you are directly assigning to the vari
582
585
583
586
` state.get(name)` returns the value of the state variable, or `None` if it doesn't exist
584
587
588
+ ` state.get_attr(name)` returns a `dict` of attribute values for the state variable, or `None`
589
+ if it doesn't exist
590
+
585
591
` state.names(domain=None)` returns a list of all state variable names (ie, `entity_id`s)
586
592
of a domain. If `domain` is not specified, it returns all HASS state variable (`entity_id`)
587
593
names.
588
594
589
- ` state.set(name, value, attr=None)` sets the state variable to the given value, with the optional attributes.
595
+ ` state.set(name, value, new_attributes=None, **kwargs)` sets the state variable to the given value,
596
+ with the optional attributes. The optional 3rd argument, `new_attributes`, should be a `dict` and
597
+ it will overwrite all the existing attributes if specified. If instead attributes are specified
598
+ using keyword arguments, then other attributes will not be affected. If no optional arguments
599
+ are provided, just the state variable value is set and the attributes are not changed. To clear
600
+ the attributes, set `new_attributes={}`.
590
601
591
602
Note that in HASS, all state variable values are coerced into strings. For example, if a state variable
592
603
has a numeric value, you might want to convert it to a numeric type (eg, using `int()` or `float()`).
604
+ Attributes keep their native type.
593
605
594
606
# ### Service Calls
595
607
@@ -605,11 +617,12 @@ parameters as the event data.
605
617
606
618
# ### Logging functions
607
619
608
- Four logging functions are provided, with increasing levels of severity :
620
+ Five logging functions are provided, with increasing levels of severity :
609
621
- ` log.debug(str)`
610
622
- ` log.info(str)`
611
623
- ` log.warning(str)`
612
624
- ` log.error(str)`
625
+ - ` print(str)` is the same as `log.debug(str)`; currently `print` doesn't support other arguments.
613
626
614
627
The [Logger](/integrations/logger/) component can be used to specify the logging level. Log messages
615
628
below the configured level will not appear in the log. Each log message function uses a log name of
0 commit comments