modify async functions name

This commit is contained in:
2024-02-27 15:52:20 +01:00
parent 8eae65de57
commit d25ed3810f
8 changed files with 154 additions and 150 deletions
+3 -3
View File
@@ -32,13 +32,13 @@ async def async_setup_entry(hass: HomeAssistant,
try:
device = Koolnova(name, port, addr, baudrate, parity, bytesize, stopbits, timeout)
# connect to modbus client
await device.connect()
await device.async_connect()
# update attributes
await device.update()
await device.async_update()
# record each area in device
_LOGGER.debug("Koolnova areas: {}".format(entry.data['areas']))
for area in entry.data['areas']:
await device.add_manual_registered_zone(name=area['Name'],
await device.async_add_manual_registered_area(name=area['Name'],
id_zone=area['Area_id'])
hass.data[DOMAIN]['device'] = device
coordinator = KoolnovaCoordinator(hass, device)
+5 -5
View File
@@ -121,7 +121,7 @@ class AreaClimateEntity(CoordinatorEntity, ClimateEntity):
_LOGGER.debug("[Climate {}] set target temp - kwargs: {}".format(self._area.id_zone, kwargs))
if "temperature" in kwargs:
target_temp = kwargs.get("temperature")
ret = await self._device.set_area_target_temp(zone_id = self._area.id_zone, temp = target_temp)
ret = await self._device.async_set_area_target_temp(zone_id = self._area.id_zone, temp = target_temp)
if not ret:
_LOGGER.error("Error sending target temperature for area id {}".format(self._area.id_zone))
else:
@@ -137,8 +137,8 @@ class AreaClimateEntity(CoordinatorEntity, ClimateEntity):
if v == fan_mode:
opt = k
break
ret = await self._device.set_area_fan_mode(zone_id = self._area.id_zone,
mode = ZoneFanMode(opt))
ret = await self._device.async_set_area_fan_mode(zone_id = self._area.id_zone,
mode = ZoneFanMode(opt))
if not ret:
_LOGGER.exception("Error setting new fan value for area id {}".format(self._area.id_zone))
await self.coordinator.async_request_refresh()
@@ -153,8 +153,8 @@ class AreaClimateEntity(CoordinatorEntity, ClimateEntity):
if v == hvac_mode:
opt = k
break
ret = await self._device.set_area_clim_mode(zone_id = self._area.id_zone,
mode = ZoneClimMode(opt))
ret = await self._device.async_set_area_clim_mode(zone_id = self._area.id_zone,
mode = ZoneClimMode(opt))
if not ret:
_LOGGER.exception("Error setting new hvac value for area id {}".format(self._area.id_zone))
await self.coordinator.async_request_refresh()
+4 -4
View File
@@ -70,11 +70,11 @@ class TestVBE4ConfigFlow(ConfigFlow, domain=DOMAIN):
timeout=self._user_inputs["Timeout"],
debug=self._user_inputs["Debug"])
try:
await self._conn.connect()
await self._conn.async_connect()
if not self._conn.connected():
raise CannotConnectError(reason="Client Modbus not connected")
#_LOGGER.debug("test communication with koolnova system")
ret, _ = await self._conn.system_status()
ret, _ = await self._conn.async_system_status()
if not ret:
self._conn.disconnect()
raise CannotConnectError(reason="Communication error")
@@ -124,12 +124,12 @@ class TestVBE4ConfigFlow(ConfigFlow, domain=DOMAIN):
if not user_input['Other_area']:
try:
if not self._conn.connected():
await self._conn.connect()
await self._conn.async_connect()
if user_input['Area_id'] > NB_ZONE_MAX:
raise ZoneIdError(reason="Area_id must be between 1 and 16")
#_LOGGER.debug("test area registered with id: {}".format(user_input['Area_id']))
# test if area is configured into koolnova system
ret, _ = await self._conn.zone_registered(user_input["Area_id"])
ret, _ = await self._conn.async_area_registered(user_input["Area_id"])
if not ret:
self._conn.disconnect()
raise AreaNotRegistredError(reason="Area Id is not registred")
+1 -1
View File
@@ -35,7 +35,7 @@ class KoolnovaCoordinator(DataUpdateCoordinator):
_LOGGER,
# Name of the data. For logging purposes.
name=DOMAIN,
update_method=device.update_all_areas,
update_method=device.async_update_all_areas,
# Polling interval. Will only be polled if there are subscribers.
update_interval=timedelta(seconds=30),
)
+62 -62
View File
@@ -260,22 +260,22 @@ class Koolnova:
_LOGGER.debug("idx found: {}".format(_idx))
return True, _idx
async def update(self) -> bool:
async def async_update(self) -> bool:
''' update values from modbus '''
_LOGGER.debug("Retreive system status ...")
ret, self._sys_state = await self._client.system_status()
ret, self._sys_state = await self._client.async_system_status()
if not ret:
_LOGGER.error("Error retreiving system status")
self._sys_state = const.SysState.SYS_STATE_OFF
_LOGGER.debug("Retreive global mode ...")
ret, self._global_mode = await self._client.global_mode()
ret, self._global_mode = await self._client.async_global_mode()
if not ret:
_LOGGER.error("Error retreiving global mode")
self._global_mode = const.GlobalMode.COLD
_LOGGER.debug("Retreive efficiency ...")
ret, self._efficiency = await self._client.efficiency()
ret, self._efficiency = await self._client.async_efficiency()
if not ret:
_LOGGER.error("Error retreiving efficiency")
self._efficiency = const.Efficiency.LOWER_EFF
@@ -285,17 +285,17 @@ class Koolnova:
_LOGGER.debug("Retreive engines ...")
for idx in range(1, const.NUM_OF_ENGINES + 1):
engine = Engine(engine_id = idx)
ret, engine.throughput = await self._client.engine_throughput(engine_id = idx)
ret, engine.state = await self._client.engine_state(engine_id = idx)
ret, engine.order_temp = await self._client.engine_order_temp(engine_id = idx)
ret, engine.throughput = await self._client.async_engine_throughput(engine_id = idx)
ret, engine.state = await self._client.async_engine_state(engine_id = idx)
ret, engine.order_temp = await self._client.async_engine_order_temp(engine_id = idx)
self._engines.append(engine)
await asyncio.sleep(0.1)
return True
async def connect(self) -> bool:
async def async_connect(self) -> bool:
''' connect to the modbus serial server '''
ret = True
await self._client.connect()
await self._client.async_connect()
if not self.connected():
ret = False
raise ClientNotConnectedError("Client Modbus connexion error")
@@ -313,11 +313,11 @@ class Koolnova:
''' close the underlying socket connection '''
self._client.disconnect()
async def discover_zones(self) -> None:
''' Set all registered zones for system '''
async def async_discover_areas(self) -> None:
''' Set all registered areas for system '''
if not self._client.connected:
raise ModbusConnexionError('Client Modbus not connected')
zones_lst = await self._client.discover_registered_zones()
zones_lst = await self._client.async_discover_registered_areas()
for zone in zones_lst:
self._areas.append(Area(name = zone['name'],
id_zone = zone['id'],
@@ -330,14 +330,14 @@ class Koolnova:
))
return
async def add_manual_registered_zone(self,
name:str = "",
id_zone:int = 0) -> bool:
''' Add zone manually to koolnova System '''
async def async_add_manual_registered_area(self,
name:str = "",
id_zone:int = 0) -> bool:
''' Add manual area to koolnova system '''
if not self._client.connected:
raise ModbusConnexionError('Client Modbus not connected')
ret, zone_dict = await self._client.zone_registered(zone_id = id_zone)
ret, zone_dict = await self._client.async_area_registered(zone_id = id_zone)
if not ret:
_LOGGER.error("Zone with ID: {} is not registered".format(id_zone))
return False
@@ -367,9 +367,9 @@ class Koolnova:
''' get specific area '''
return self._areas[zone_id - 1]
async def update_area(self, zone_id:int = 0) -> bool:
async def async_update_area(self, zone_id:int = 0) -> bool:
""" update specific area from zone_id """
ret, infos = await self._client.zone_registered(zone_id = zone_id)
ret, infos = await self._client.async_area_registered(zone_id = zone_id)
if not ret:
_LOGGER.error("Error retreiving area ({}) values".format(zone_id))
return ret, None
@@ -385,10 +385,10 @@ class Koolnova:
break
return ret, self._areas[zone_id - 1]
async def update_all_areas(self) -> list:
async def async_update_all_areas(self) -> list:
""" update all areas registered and all engines values """
##### Areas
_ret, _vals = await self._client.areas_registered()
_ret, _vals = await self._client.async_areas_registered()
if not _ret:
_LOGGER.error("Error retreiving areas values")
return None
@@ -406,24 +406,24 @@ class Koolnova:
##### Engines
for _idx in range(1, const.NUM_OF_ENGINES + 1):
ret, self._engines[_idx - 1].throughput = await self._client.engine_throughput(engine_id = _idx)
ret, self._engines[_idx - 1].state = await self._client.engine_state(engine_id = _idx)
ret, self._engines[_idx - 1].order_temp = await self._client.engine_order_temp(engine_id = _idx)
ret, self._engines[_idx - 1].throughput = await self._client.async_engine_throughput(engine_id = _idx)
ret, self._engines[_idx - 1].state = await self._client.async_engine_state(engine_id = _idx)
ret, self._engines[_idx - 1].order_temp = await self._client.async_engine_order_temp(engine_id = _idx)
##### Global mode
ret, self._global_mode = await self._client.global_mode()
ret, self._global_mode = await self._client.async_global_mode()
if not ret:
_LOGGER.error("Error retreiving global mode")
self._global_mode = const.GlobalMode.COLD
##### Efficiency
ret, self._efficiency = await self._client.efficiency()
ret, self._efficiency = await self._client.async_efficiency()
if not ret:
_LOGGER.error("Error retreiving efficiency")
self._efficiency = const.Efficiency.LOWER_EFF
##### Sys state
ret, self._sys_state = await self._client.system_status()
ret, self._sys_state = await self._client.async_system_status()
if not ret:
_LOGGER.error("Error retreiving system status")
self._sys_state = const.SysState.SYS_STATE_OFF
@@ -458,14 +458,14 @@ class Koolnova:
''' Get Global Mode '''
return self._global_mode
async def set_global_mode(self,
async def async_set_global_mode(self,
val:const.GlobalMode,
) -> None:
''' Set Global Mode '''
_LOGGER.debug("set global mode : {}".format(val))
if not isinstance(val, const.GlobalMode):
raise AssertionError('Input variable must be Enum GlobalMode')
ret = await self._client.set_global_mode(val)
ret = await self._client.async_set_global_mode(val)
if not ret:
_LOGGER.error("[GLOBAL] Error writing {} to modbus".format(val))
raise UpdateValueError('Error writing to modbus updated value')
@@ -476,14 +476,14 @@ class Koolnova:
''' Get Efficiency '''
return self._efficiency
async def set_efficiency(self,
val:const.Efficiency,
) -> None:
async def async_set_efficiency(self,
val:const.Efficiency,
) -> None:
''' Set Efficiency '''
_LOGGER.debug("set efficiency : {}".format(val))
if not isinstance(val, const.Efficiency):
raise AssertionError('Input variable must be Enum Efficiency')
ret = await self._client.set_efficiency(val)
ret = await self._client.async_set_efficiency(val)
if not ret:
_LOGGER.error("[EFF] Error writing {} to modbus".format(val))
raise UpdateValueError('Error writing to modbus updated value')
@@ -494,72 +494,72 @@ class Koolnova:
''' Get System State '''
return self._sys_state
async def set_sys_state(self,
val:const.SysState,
) -> None:
async def async_set_sys_state(self,
val:const.SysState,
) -> None:
''' Set System State '''
if not isinstance(val, const.SysState):
raise AssertionError('Input variable must be Enum SysState')
_LOGGER.debug("set system state : {}".format(val))
ret = await self._client.set_system_status(val)
ret = await self._client.async_set_system_status(val)
if not ret:
_LOGGER.error("[SYS_STATE] Error writing {} to modbus".format(val))
raise UpdateValueError('Error writing to modbus updated value')
self._sys_state = val
async def get_area_temp(self,
zone_id:int,
) -> float:
async def async_get_area_temp(self,
zone_id:int,
) -> float:
""" get current temp of specific Area """
_ret, _idx = self._area_defined(id_search = zone_id)
if not _ret:
_LOGGER.error("Area not defined ...")
return False
ret, temp = await self._client.area_temp(id_zone = zone_id)
ret, temp = await self._client.async_area_temp(id_zone = zone_id)
if not ret:
_LOGGER.error("Error reading temp for area with ID: {}".format(zone_id))
return False
self._areas[_idx].real_temp = temp
return temp
async def set_area_target_temp(self,
zone_id:int,
temp:float,
) -> bool:
async def async_set_area_target_temp(self,
zone_id:int,
temp:float,
) -> bool:
""" set target temp of specific area """
_ret, _idx = self._area_defined(id_search = zone_id)
if not _ret:
_LOGGER.error("Area not defined ...")
return False
ret = await self._client.set_area_target_temp(zone_id = zone_id, val = temp)
ret = await self._client.async_set_area_target_temp(zone_id = zone_id, val = temp)
if not ret:
_LOGGER.error("Error writing target temp for area with ID: {}".format(zone_id))
return False
self._areas[_idx].order_temp = temp
return True
async def get_area_target_temp(self,
zone_id:int,
) -> float:
async def async_get_area_target_temp(self,
zone_id:int,
) -> float:
""" get target temp of specific area """
_ret, _idx = self._area_defined(id_search = zone_id)
if not _ret:
_LOGGER.error("Area not defined ...")
return False
ret, temp = await self._client.area_target_temp(id_zone = zone_id)
ret, temp = await self._client.async_area_target_temp(id_zone = zone_id)
if not ret:
_LOGGER.error("Error reading target temp for area with ID: {}".format(zone_id))
return 0.0
self._areas[_idx].order_temp = temp
return temp
async def set_area_clim_mode(self,
zone_id:int,
mode:const.ZoneClimMode,
) -> bool:
async def async_set_area_clim_mode(self,
zone_id:int,
mode:const.ZoneClimMode,
) -> bool:
""" set climate mode for specific area """
_ret, _idx = self._area_defined(id_search = zone_id)
if not _ret:
@@ -568,7 +568,7 @@ class Koolnova:
if mode == const.ZoneClimMode.OFF:
_LOGGER.debug("Set area state to OFF")
ret = await self._client.set_area_state(id_zone = zone_id, val = const.ZoneState.STATE_OFF)
ret = await self._client.async_set_area_state(id_zone = zone_id, val = const.ZoneState.STATE_OFF)
if not ret:
_LOGGER.error("Error writing area state for area with ID: {}".format(zone_id))
return False
@@ -577,23 +577,23 @@ class Koolnova:
if self._areas[_idx].state == const.ZoneState.STATE_OFF:
_LOGGER.debug("Set area state to ON")
# update area state
ret = await self._client.set_area_state(id_zone = zone_id, val = const.ZoneState.STATE_ON)
ret = await self._client.async_set_area_state(id_zone = zone_id, val = const.ZoneState.STATE_ON)
if not ret:
_LOGGER.error("Error writing area state for area with ID: {}".format(zone_id))
return False
_LOGGER.debug("clim mode ? {}".format(mode))
# update clim mode
ret = await self._client.set_area_clim_mode(id_zone = zone_id, val = mode)
ret = await self._client.async_set_area_clim_mode(id_zone = zone_id, val = mode)
if not ret:
_LOGGER.error("Error writing climate mode for area with ID: {}".format(zone_id))
return False
self._areas[_idx].clim_mode = mode
return True
async def set_area_fan_mode(self,
zone_id:int,
mode:const.ZoneFanMode,
) -> bool:
async def async_set_area_fan_mode(self,
zone_id:int,
mode:const.ZoneFanMode,
) -> bool:
""" set fan mode for specific area """
# test if area id is defined
_ret, _idx = self._area_defined(id_search = zone_id)
@@ -607,7 +607,7 @@ class Koolnova:
else:
_LOGGER.debug("fan mode ? {}".format(mode))
# writing new value to modbus
ret = await self._client.set_area_fan_mode(id_zone = zone_id, val = mode)
ret = await self._client.async_set_area_fan_mode(id_zone = zone_id, val = mode)
if not ret:
_LOGGER.error("Error writing fan mode for area with ID: {}".format(zone_id))
return False
+63 -61
View File
@@ -128,7 +128,7 @@ class Operations:
return False
return ret
async def connect(self) -> None:
async def async_connect(self) -> None:
''' connect to the modbus serial server '''
await self._client.connect()
@@ -141,7 +141,7 @@ class Operations:
if self._client.connected:
self._client.close()
async def discover_registered_zones(self) -> list:
async def async_discover_registered_areas(self) -> list:
''' Discover all areas registered to the system '''
regs, ret = await self.__async_read_registers(start_reg=const.REG_START_ZONE,
count=const.NB_ZONE_MAX * const.NUM_REG_PER_ZONE)
@@ -171,10 +171,10 @@ class Operations:
zones_lst.append(zone_dict)
return zones_lst
async def zone_registered(self,
zone_id:int = 0,
) -> (bool, dict):
''' Get Zone Status from Id '''
async def async_area_registered(self,
zone_id:int = 0,
) -> (bool, dict):
''' Get Area status from id '''
#_LOGGER.debug("Area : {}".format(zone_id))
if zone_id > const.NB_ZONE_MAX or zone_id == 0:
raise ZoneIdError('Zone Id must be between 1 to {}'.format(const.NB_ZONE_MAX))
@@ -195,7 +195,7 @@ class Operations:
zone_dict['real_temp'] = regs[3]/2
return True, zone_dict
async def areas_registered(self) -> (bool, dict):
async def async_areas_registered(self) -> (bool, dict):
""" Get all areas values """
_areas_dict:dict = {}
# retreive all areas (registered and unregistered)
@@ -219,7 +219,7 @@ class Operations:
_areas_dict[area_idx + 1] = _area_dict
return True, _areas_dict
async def system_status(self) -> (bool, const.SysState):
async def async_system_status(self) -> (bool, const.SysState):
''' Read system status register '''
reg, ret = await self.__async_read_register(const.REG_SYS_STATE)
if not ret:
@@ -227,16 +227,16 @@ class Operations:
reg = 0
return ret, const.SysState(reg)
async def set_system_status(self,
opt:const.SysState,
) -> bool:
async def async_set_system_status(self,
opt:const.SysState,
) -> bool:
''' Write system status '''
ret = await self.__async_write_register(reg = const.REG_SYS_STATE, val = int(opt))
if not ret:
_LOGGER.error('Error writing system status')
return ret
async def global_mode(self) -> (bool, const.GlobalMode):
async def async_global_mode(self) -> (bool, const.GlobalMode):
''' Read global mode '''
reg, ret = await self.__async_read_register(const.REG_GLOBAL_MODE)
if not ret:
@@ -244,16 +244,16 @@ class Operations:
reg = 0
return ret, const.GlobalMode(reg)
async def set_global_mode(self,
opt:const.GlobalMode,
) -> bool:
async def async_set_global_mode(self,
opt:const.GlobalMode,
) -> bool:
''' Write global mode '''
ret = await self.__async_write_register(reg = const.REG_GLOBAL_MODE, val = int(opt))
if not ret:
_LOGGER.error('Error writing global mode')
return ret
async def efficiency(self) -> (bool, const.Efficiency):
async def async_efficiency(self) -> (bool, const.Efficiency):
''' read efficiency/speed '''
reg, ret = await self.__async_read_register(const.REG_EFFICIENCY)
if not ret:
@@ -261,20 +261,20 @@ class Operations:
reg = 0
return ret, const.Efficiency(reg)
async def set_efficiency(self,
opt:const.GlobalMode,
) -> bool:
async def async_set_efficiency(self,
opt:const.GlobalMode,
) -> bool:
''' Write efficiency '''
ret = await self.__async_write_register(reg = const.REG_EFFICIENCY, val = int(opt))
if not ret:
_LOGGER.error('Error writing efficiency')
return ret
async def engines_throughput(self) -> (bool, list):
async def async_engines_throughput(self) -> (bool, list):
''' read engines throughput AC1, AC2, AC3, AC4 '''
engines_lst = []
regs, ret = await self.__async_read_registers(const.REG_START_FLOW_ENGINE,
const.NUM_OF_ENGINES)
const.NUM_OF_ENGINES)
if ret:
for idx, reg in enumerate(regs):
engines_lst.append(const.FlowEngine(reg))
@@ -282,9 +282,9 @@ class Operations:
_LOGGER.error('Error retreive engines throughput')
return ret, engines_lst
async def engine_throughput(self,
engine_id:int = 0,
) -> (bool, int):
async def async_engine_throughput(self,
engine_id:int = 0,
) -> (bool, int):
''' read engine throughput specified by id '''
if engine_id < 1 or engine_id > 4:
raise UnitIdError("engine Id must be between 1 and 4")
@@ -294,9 +294,10 @@ class Operations:
reg = 0
return ret, reg
async def engine_state(self,
engine_id:int = 0,
) -> (bool, const.FlowEngine):
async def async_engine_state(self,
engine_id:int = 0,
) -> (bool, const.FlowEngine):
''' read engine state specified by id '''
if engine_id < 1 or engine_id > 4:
raise UnitIdError("Engine id must be between 1 and 4")
reg, ret = await self.__async_read_register(const.REG_START_FLOW_STATE_ENGINE + (engine_id - 1))
@@ -305,9 +306,10 @@ class Operations:
reg = 0
return ret, const.FlowEngine(reg)
async def engine_order_temp(self,
engine_id:int = 0,
) -> (bool, float):
async def async_engine_order_temp(self,
engine_id:int = 0,
) -> (bool, float):
''' read engine order temperature specified by id '''
if engine_id < 1 or engine_id > 4:
raise UnitIdError("Engine id must be between 1 and 4")
reg, ret = await self.__async_read_register(const.REG_START_ORDER_TEMP + (engine_id - 1))
@@ -316,7 +318,7 @@ class Operations:
reg = 0
return ret, reg / 2
async def engine_orders_temp(self) -> (bool, list):
async def async_engine_orders_temp(self) -> (bool, list):
''' read orders temperature for engines : AC1, AC2, AC3, AC4 '''
engines_lst = []
regs, ret = await self.__async_read_registers(const.REG_START_ORDER_TEMP, const.NUM_OF_ENGINES)
@@ -327,10 +329,10 @@ class Operations:
_LOGGER.error('error reading engines order temp registers')
return ret, engines_lst
async def set_area_target_temp(self,
zone_id:int = 0,
val:float = 0.0,
) -> bool:
async def async_set_area_target_temp(self,
zone_id:int = 0,
val:float = 0.0,
) -> bool:
''' Set area target temperature '''
if zone_id > const.NB_ZONE_MAX or zone_id == 0:
raise ZoneIdError('Zone Id must be between 1 to 16')
@@ -343,9 +345,9 @@ class Operations:
return ret
async def area_temp(self,
id_zone:int = 0,
) -> (bool, float):
async def async_area_temp(self,
id_zone:int = 0,
) -> (bool, float):
""" get temperature of specific area id """
reg, ret = await self.__async_read_register(reg = const.REG_START_ZONE + (4 * (id_zone - 1)) + const.REG_TEMP_REAL)
if not ret:
@@ -353,9 +355,9 @@ class Operations:
reg = 0
return ret, reg / 2
async def area_target_temp(self,
id_zone:int = 0,
) -> (bool, float):
async def async_area_target_temp(self,
id_zone:int = 0,
) -> (bool, float):
""" get target temperature of specific area id """
reg, ret = await self.__async_read_register(reg = const.REG_START_ZONE + (4 * (id_zone - 1)) + const.REG_TEMP_ORDER)
if not ret:
@@ -363,9 +365,9 @@ class Operations:
reg = 0
return ret, reg / 2
async def area_clim_and_fan_mode(self,
id_zone:int = 0,
) -> (bool, const.ZoneFanMode, const.ZoneClimMode):
async def async_area_clim_and_fan_mode(self,
id_zone:int = 0,
) -> (bool, const.ZoneFanMode, const.ZoneClimMode):
""" get climate and fan mode of specific area id """
reg, ret = await self.__async_read_register(reg = const.REG_START_ZONE + (4 * (id_zone - 1)) + const.REG_STATE_AND_FLOW)
if not ret:
@@ -373,9 +375,9 @@ class Operations:
reg = 0
return ret, const.ZoneFanMode((reg & 0xF0) >> 4), const.ZoneClimMode(reg & 0x0F)
async def area_state_and_register(self,
id_zone:int = 0,
) -> (bool, const.ZoneRegister, const.ZoneState):
async def async_area_state_and_register(self,
id_zone:int = 0,
) -> (bool, const.ZoneRegister, const.ZoneState):
""" get area state and register """
reg, ret = await self.__async_read_register(reg = const.REG_START_ZONE + (4 * (id_zone - 1)) + const.REG_LOCK_ZONE)
if not ret:
@@ -383,16 +385,16 @@ class Operations:
reg = 0
return ret, const.ZoneRegister(reg >> 1), const.ZoneState(reg & 0b01)
async def set_area_state(self,
id_zone:int = 0,
val:const.ZoneState = const.ZoneState.STATE_OFF,
) -> bool:
async def async_set_area_state(self,
id_zone:int = 0,
val:const.ZoneState = const.ZoneState.STATE_OFF,
) -> bool:
""" set area state """
register:const.ZoneRegister = const.ZoneRegister.REGISTER_OFF
if id_zone > const.NB_ZONE_MAX or id_zone == 0:
raise ZoneIdError('Area Id must be between 1 to 16')
# retreive values to combine the new state with register read
ret, register, _ = await self.area_state_and_register(id_zone = id_zone)
ret, register, _ = await self.async_area_state_and_register(id_zone = id_zone)
if not ret:
_LOGGER.error("Error reading state and register mode")
return ret
@@ -404,16 +406,16 @@ class Operations:
return True
async def set_area_clim_mode(self,
id_zone:int = 0,
val:const.ZoneClimMode = const.ZoneClimMode.OFF,
async def async_set_area_clim_mode(self,
id_zone:int = 0,
val:const.ZoneClimMode = const.ZoneClimMode.OFF,
) -> bool:
""" set area clim mode """
fan:const.ZoneFanMode = const.ZoneFanMode.FAN_OFF
if id_zone > const.NB_ZONE_MAX or id_zone == 0:
raise ZoneIdError('Zone Id must be between 1 to 16')
# retreive values to combine the new climate mode with fan mode read
ret, fan, _ = await self.area_clim_and_fan_mode(id_zone = id_zone)
ret, fan, _ = await self.async_area_clim_and_fan_mode(id_zone = id_zone)
if not ret:
_LOGGER.error("Error reading fan and clim mode")
return ret
@@ -425,16 +427,16 @@ class Operations:
return ret
async def set_area_fan_mode(self,
id_zone:int = 0,
val:const.ZoneFanMode = const.ZoneFanMode.FAN_OFF,
) -> bool:
async def async_set_area_fan_mode(self,
id_zone:int = 0,
val:const.ZoneFanMode = const.ZoneFanMode.FAN_OFF,
) -> bool:
""" set area fan mode """
clim:const.ZoneClimMode = const.ZoneClimMode.OFF
if id_zone > const.NB_ZONE_MAX or id_zone == 0:
raise ZoneIdError('Zone Id must be between 1 to 16')
# retreive values to combine the new fan mode with climate mode read
ret, _, clim = await self.area_clim_and_fan_mode(id_zone = id_zone)
ret, _, clim = await self.async_area_clim_and_fan_mode(id_zone = id_zone)
if not ret:
_LOGGER.error("Error reading fan and clim mode")
return ret
+12 -10
View File
@@ -63,11 +63,11 @@ class GlobalModeSelect(CoordinatorEntity, SelectEntity):
self._attr_device_info = device.device_info
self._attr_icon = "mdi:cog-clockwise"
self._attr_unique_id = f"{DOMAIN}-Global-HVACMode-select"
self.select_option(
self.__select_option(
GLOBAL_MODE_TRANSLATION[int(self._device.global_mode)]
)
def select_option(self, option: str) -> None:
def __select_option(self, option: str) -> None:
""" Change the selected option. """
self._attr_current_option = option
@@ -78,15 +78,16 @@ class GlobalModeSelect(CoordinatorEntity, SelectEntity):
if v == option:
opt = k
break
await self._device.set_global_mode(GlobalMode(opt))
self.select_option(option)
await self._device.async_set_global_mode(GlobalMode(opt))
self.__select_option(option)
await self.coordinator.async_request_refresh()
@callback
def _handle_coordinator_update(self) -> None:
""" Handle updated data from the coordinator
Retrieve latest state of global mode """
_LOGGER.debug("[UPDATE] Global Mode: {}".format(self.coordinator.data['glob']))
self.select_option(
self.__select_option(
GLOBAL_MODE_TRANSLATION[int(self.coordinator.data['glob'])]
)
self.async_write_ha_state()
@@ -107,11 +108,11 @@ class EfficiencySelect(CoordinatorEntity, SelectEntity):
self._attr_device_info = device.device_info
self._attr_icon = "mdi:wind-power-outline"
self._attr_unique_id = f"{DOMAIN}-Global-HVACEff-select"
self.select_option(
self.__select_option(
EFF_TRANSLATION[int(self._device.efficiency)]
)
def select_option(self,
def __select_option(self,
option: str,
) -> None:
""" Change the selected option. """
@@ -127,15 +128,16 @@ class EfficiencySelect(CoordinatorEntity, SelectEntity):
if v == option:
opt = k
break
await self._device.set_efficiency(Efficiency(opt))
self.select_option(option)
await self._device.async_set_efficiency(Efficiency(opt))
self.__select_option(option)
await self.coordinator.async_request_refresh()
@callback
def _handle_coordinator_update(self) -> None:
""" Handle updated data from the coordinator
Retrieve latest state of global efficiency """
_LOGGER.debug("[UPDATE] Efficiency: {}".format(self.coordinator.data['eff']))
self.select_option(
self.__select_option(
EFF_TRANSLATION[int(self.coordinator.data['eff'])]
)
self.async_write_ha_state()
+4 -4
View File
@@ -73,18 +73,18 @@ class SystemStateSwitch(CoordinatorEntity, SwitchEntity):
async def async_turn_on(self, **kwargs):
""" Turn the entity on. """
_LOGGER.debug("Turn on system")
await self._device.set_sys_state(SysState.SYS_STATE_ON)
await self._device.async_set_sys_state(SysState.SYS_STATE_ON)
self._attr_is_on = True
self._attr_state = STATE_ON
self.async_write_ha_state()
await self.coordinator.async_request_refresh()
async def async_turn_off(self, **kwargs):
""" Turn the entity off. """
_LOGGER.debug("Turn off system")
await self._device.set_sys_state(SysState.SYS_STATE_OFF)
await self._device.async_set_sys_state(SysState.SYS_STATE_OFF)
self._attr_is_on = False
self._attr_state = STATE_OFF
self.async_write_ha_state()
await self.coordinator.async_request_refresh()
@callback
def _handle_coordinator_update(self) -> None: