@@ -140,14 +140,18 @@ def icon(self) -> str:
140140 return self .data ['icon' ]
141141
142142 @property
143- def state (self ) -> float :
144- """Return the last reported state for this Crownstone."""
145- return self .data ['currentSwitchState ' ]['switchState' ]
143+ def state (self ) -> int :
144+ """Return the last reported switch state (0 - 100) of this Crownstone."""
145+ return self .data ['currentSwitchStateV2 ' ]['switchState' ]
146146
147147 @state .setter
148- def state (self , value : float ) -> None :
149- """Set a new state for this Crownstone."""
150- self .data ['currentSwitchState' ]['switchState' ] = value
148+ def state (self , value : int ) -> None :
149+ """
150+ Set a new switch state (0 - 100) of this Crownstone.
151+
152+ Only updates state in cloud, does not send a switch command to the actual Crownstone.
153+ """
154+ self .data ['currentSwitchStateV2' ]['switchState' ] = value
151155
152156 def update_abilities (self ) -> None :
153157 """Add/update the abilities for this Crownstone."""
@@ -163,8 +167,8 @@ async def async_turn_on(self) -> None:
163167 # make sure to use the context of what the object was created in.
164168 self .cloud .login_manager .set_context (self ._context )
165169 # send a command to the cloud to turn the Crownstone on.
166- await self .cloud .request_handler .put (
167- 'Stones' , 'setSwitchStateRemotely ' , model_id = self .cloud_id , command = 'switchState' , value = 1
170+ await self .cloud .request_handler .post (
171+ 'Stones' , 'switch ' , model_id = self .cloud_id , json = { "type" : "TURN_ON" }
168172 )
169173
170174 async def async_turn_off (self ) -> None :
@@ -176,8 +180,8 @@ async def async_turn_off(self) -> None:
176180 # make sure to use the context of what the object was created in.
177181 self .cloud .login_manager .set_context (self ._context )
178182 # send a command to the cloud to turn the Crownstone off.
179- await self .cloud .request_handler .put (
180- 'Stones' , 'setSwitchStateRemotely ' , model_id = self .cloud_id , command = 'switchState' , value = 0
183+ await self .cloud .request_handler .post (
184+ 'Stones' , 'switch ' , model_id = self .cloud_id , json = { "type" : "TURN_OFF" }
181185 )
182186
183187 async def async_set_brightness (self , brightness : int ) -> None :
@@ -195,10 +199,9 @@ async def async_set_brightness(self, brightness: int) -> None:
195199 if brightness < 0 or brightness > 100 :
196200 raise ValueError ("Enter a value between 0 and 100" )
197201 else :
198- # cloud still uses float value from 0 ... 1
199- float_val = brightness / 100
200- await self .cloud .request_handler .put (
201- 'Stones' , 'setSwitchStateRemotely' , model_id = self .cloud_id , command = 'switchState' , value = float_val
202+ await self .cloud .request_handler .post (
203+ 'Stones' , 'switch' , model_id = self .cloud_id , json = {"type" : "PERCENTAGE" ,"percentage" : brightness }
202204 )
203205 else :
204206 _LOGGER .warning ("Dimming is not enabled for this crownstone. Go to the crownstone app to enable it" )
207+ # TODO: raise error, or just try to set brightness anyway?
0 commit comments