2424 CannotConnectError ,
2525 Hub as VictronVenusHub ,
2626 Metric as VictronVenusMetric ,
27- Switch as VictronVenusSwitch ,
27+ WritableMetric as VictronVenusWritableMetric ,
2828 Device as VictronVenusDevice ,
2929 MetricKind ,
3030 GenericOnOff ,
@@ -126,7 +126,7 @@ def creatre_entity(self, device: VictronVenusDevice, metric: VictronVenusMetric,
126126 return VictronSensor (device , metric , info , self .update_frequency_seconds )
127127 elif metric .metric_kind == MetricKind .BINARY_SENSOR :
128128 return VictronBinarySensor (device , metric , info , self .update_frequency_seconds )
129- assert isinstance (metric , VictronVenusSwitch ), f"Expected metric to be a VictronVenusSwitch . Got { type (metric )} "
129+ assert isinstance (metric , VictronVenusWritableMetric ), f"Expected metric to be a VictronVenusWritableMetric . Got { type (metric )} "
130130 if metric .metric_kind == MetricKind .SWITCH :
131131 return VictronSwitch (device , metric , info , self .update_frequency_seconds )
132132 elif metric .metric_kind == MetricKind .NUMBER :
@@ -166,13 +166,13 @@ class VictronSwitch(VictronBaseEntity, SwitchEntity):
166166 def __init__ (
167167 self ,
168168 device : VictronVenusDevice ,
169- switch : VictronVenusSwitch ,
169+ writable_metric : VictronVenusWritableMetric ,
170170 device_info : DeviceInfo ,
171171 update_frequency_seconds : int ,
172172 ) -> None :
173173 """Initialize the switch."""
174- self ._attr_is_on = switch .value == GenericOnOff .On
175- super ().__init__ (device , switch , device_info , "switch" , update_frequency_seconds )
174+ self ._attr_is_on = writable_metric .value == GenericOnOff .On
175+ super ().__init__ (device , writable_metric , device_info , "switch" , update_frequency_seconds )
176176
177177 def __repr__ (self ) -> str :
178178 """Return a string representation of the sensor."""
@@ -186,14 +186,14 @@ async def _on_update_task(self, metric: VictronVenusMetric):
186186
187187 async def async_turn_on (self , ** kwargs : Any ) -> None :
188188 """Turn the switch on."""
189- assert isinstance (self ._metric , VictronVenusSwitch )
189+ assert isinstance (self ._metric , VictronVenusWritableMetric )
190190 _LOGGER .info ("Turning on switch: %s" , self ._attr_unique_id )
191191 self ._metric .set (GenericOnOff .On )
192192 self .async_write_ha_state ()
193193
194194 async def async_turn_off (self , ** kwargs : Any ) -> None :
195195 """Turn the switch off."""
196- assert isinstance (self ._metric , VictronVenusSwitch )
196+ assert isinstance (self ._metric , VictronVenusWritableMetric )
197197 _LOGGER .info ("Turning off switch: %s" , self ._attr_unique_id )
198198 self ._metric .set (GenericOnOff .Off )
199199 self .async_write_ha_state ()
@@ -204,19 +204,19 @@ class VictronNumber(VictronBaseEntity, NumberEntity):
204204 def __init__ (
205205 self ,
206206 device : VictronVenusDevice ,
207- switch : VictronVenusSwitch ,
207+ writable_metric : VictronVenusWritableMetric ,
208208 device_info : DeviceInfo ,
209209 update_frequency_seconds : int ,
210210 ) -> None :
211211 """Initialize the number entity."""
212- self ._attr_native_value = switch .value
213- if isinstance (switch .min_value , int ) or isinstance (switch .min_value , float ):
214- self ._attr_native_min_value = switch .min_value
215- if isinstance (switch .max_value , int ) or isinstance (switch .max_value , float ):
216- self ._attr_native_max_value = switch .max_value
217- if isinstance (switch . increment , int ) or isinstance (switch . increment , float ):
218- self ._attr_native_step = switch . increment
219- super ().__init__ (device , switch , device_info , "number" , update_frequency_seconds )
212+ self ._attr_native_value = writable_metric .value
213+ if isinstance (writable_metric .min_value , int ) or isinstance (writable_metric .min_value , float ):
214+ self ._attr_native_min_value = writable_metric .min_value
215+ if isinstance (writable_metric .max_value , int ) or isinstance (writable_metric .max_value , float ):
216+ self ._attr_native_max_value = writable_metric .max_value
217+ if isinstance (writable_metric . step , int ) or isinstance (writable_metric . step , float ):
218+ self ._attr_native_step = writable_metric . step
219+ super ().__init__ (device , writable_metric , device_info , "number" , update_frequency_seconds )
220220
221221 def __repr__ (self ) -> str :
222222 """Return a string representation of the sensor."""
@@ -233,7 +233,7 @@ def native_value(self):
233233
234234 async def async_set_native_value (self , value : float ) -> None :
235235 """Set a new value."""
236- assert isinstance (self ._metric , VictronVenusSwitch )
236+ assert isinstance (self ._metric , VictronVenusWritableMetric )
237237 _LOGGER .info ("Setting number %s on switch: %s" , value , self ._attr_unique_id )
238238 self ._metric .set (value )
239239 self .async_write_ha_state ()
@@ -270,14 +270,14 @@ class VictronSelect(VictronBaseEntity, SelectEntity):
270270 def __init__ (
271271 self ,
272272 device : VictronVenusDevice ,
273- switch : VictronVenusSwitch ,
273+ writable_metric : VictronVenusWritableMetric ,
274274 device_info : DeviceInfo ,
275275 update_frequency_seconds : int ,
276276 ) -> None :
277277 """Initialize the switch."""
278- self ._attr_options = switch .enum_values
279- self ._attr_current_option = self ._map_value_to_state (switch .value )
280- super ().__init__ (device , switch , device_info , "select" , update_frequency_seconds )
278+ self ._attr_options = writable_metric .enum_values
279+ self ._attr_current_option = self ._map_value_to_state (writable_metric .value )
280+ super ().__init__ (device , writable_metric , device_info , "select" , update_frequency_seconds )
281281
282282 def __repr__ (self ) -> str :
283283 """Return a string representation of the sensor."""
@@ -294,7 +294,7 @@ async def async_select_option(self, option: str) -> None:
294294 _LOGGER .info ("Setting switch %s to %s failed as option not supported. supported options are: %s" , self ._attr_unique_id , option , self ._metric .enum_values )
295295 return
296296 _LOGGER .info ("Setting switch %s to %s" , self ._attr_unique_id , option )
297- assert isinstance (self ._metric , VictronVenusSwitch )
297+ assert isinstance (self ._metric , VictronVenusWritableMetric )
298298 self ._metric .set (option )
299299 self .async_write_ha_state ()
300300
0 commit comments