@@ -40,7 +40,7 @@ def __init__(
4040 super ().__init__ (mac , address , controller , loaded_callback )
4141 self ._switch_subscription : Callable [[], None ] | None = None
4242 self ._switch_state : bool | None = None
43- self ._switch : bool | None = None
43+ self ._switch : bool = False
4444
4545 async def load (self ) -> bool :
4646 """Load and activate Switch node features."""
@@ -107,26 +107,21 @@ async def _switch_group(self, response: PlugwiseResponse) -> bool:
107107 async def _switch_state_update (
108108 self , switch_state : bool , timestamp : datetime
109109 ) -> None :
110- """Process motion state update."""
110+ """Process switch state update."""
111111 _LOGGER .debug (
112112 "_switch_state_update for %s: %s -> %s" ,
113113 self .name ,
114114 self ._switch_state ,
115115 switch_state ,
116116 )
117117 state_update = False
118- # Switch on
119- if switch_state :
120- self ._set_cache (CACHE_SWITCH_STATE , "True" )
121- if self ._switch_state is None or not self ._switch :
122- self ._switch_state = True
123- state_update = True
124- else :
125- # Switch off
126- self ._set_cache (CACHE_SWITCH_STATE , "False" )
127- if self ._switch is None or self ._switch :
128- self ._switch_state = False
129- state_update = True
118+ # Update cache
119+ self ._set_cache (CACHE_SWITCH_STATE , str (switch_state ))
120+ # Check for a state change
121+ if self ._switch_state != switch_state :
122+ self ._switch_state = switch_state
123+ state_update = True
124+
130125 self ._set_cache (CACHE_SWITCH_TIMESTAMP , timestamp )
131126 if state_update :
132127 self ._switch = switch_state
0 commit comments