44
55from collections .abc import Callable
66from dataclasses import dataclass
7- from typing import TYPE_CHECKING , Any , Final , cast
7+ from typing import TYPE_CHECKING , Final , cast
88
99from aioshelly .block_device import Block
1010from aioshelly .const import RPC_GENERATIONS
3434 MODEL_LINKEDGO_ST1820_THERMOSTAT ,
3535 MODEL_TOP_EV_CHARGER_EVE01 ,
3636 ROLE_GENERIC ,
37+ TRV_CHANNEL ,
3738 VIRTUAL_NUMBER_MODE_MAP ,
3839)
3940from .coordinator import ShellyBlockCoordinator , ShellyConfigEntry , ShellyRpcCoordinator
6263class BlockNumberDescription (BlockEntityDescription , NumberEntityDescription ):
6364 """Class to describe a BLOCK sensor."""
6465
65- rest_path : str = ""
66- rest_arg : str = ""
67-
6866
6967@dataclass (frozen = True , kw_only = True )
7068class RpcNumberDescription (RpcEntityDescription , NumberEntityDescription ):
@@ -178,7 +176,7 @@ async def async_set_native_value(self, value: float) -> None:
178176 self .async_write_ha_state ()
179177
180178
181- NUMBERS : dict [tuple [str , str ], BlockNumberDescription ] = {
179+ BLOCK_NUMBERS : dict [tuple [str , str ], BlockNumberDescription ] = {
182180 ("device" , "valvePos" ): BlockNumberDescription (
183181 key = "device|valvepos" ,
184182 translation_key = "valve_position" ,
@@ -189,8 +187,6 @@ async def async_set_native_value(self, value: float) -> None:
189187 native_max_value = 100 ,
190188 native_step = 1 ,
191189 mode = NumberMode .SLIDER ,
192- rest_path = "thermostat/0" ,
193- rest_arg = "pos" ,
194190 ),
195191}
196192
@@ -357,7 +353,7 @@ def _async_setup_block_entry(
357353 hass ,
358354 config_entry ,
359355 async_add_entities ,
360- NUMBERS ,
356+ BLOCK_NUMBERS ,
361357 BlockSleepingNumber ,
362358 )
363359
@@ -426,18 +422,11 @@ def native_value(self) -> float | None:
426422
427423 async def async_set_native_value (self , value : float ) -> None :
428424 """Set value."""
429- # Example for Shelly Valve: http://192.168.188.187/thermostat/0?pos=13.0
430- await self ._set_state_full_path (
431- self .entity_description .rest_path ,
432- {self .entity_description .rest_arg : value },
425+ LOGGER .debug (
426+ "Setting thermostat position for entity %s to %s" , self .name , value
433427 )
434- self .async_write_ha_state ()
435-
436- async def _set_state_full_path (self , path : str , params : Any ) -> Any :
437- """Set block state (HTTP request)."""
438- LOGGER .debug ("Setting state for entity %s, state: %s" , self .name , params )
439428 try :
440- return await self .coordinator .device .http_request ( "get" , path , params )
429+ await self .coordinator .device .set_thermostat_state ( TRV_CHANNEL , pos = value )
441430 except DeviceConnectionError as err :
442431 self .coordinator .last_update_success = False
443432 raise HomeAssistantError (
@@ -450,3 +439,4 @@ async def _set_state_full_path(self, path: str, params: Any) -> Any:
450439 ) from err
451440 except InvalidAuthError :
452441 await self .coordinator .async_shutdown_device_and_start_reauth ()
442+ self .async_write_ha_state ()
0 commit comments