code correction
This commit is contained in:
1 parent
93d8b339ec
commit
6c6b035cf5
7 files changed
+245
-238
No files matched your search
@@ -1,4 +1,4 @@
|
||||
""" local API to manage system, units and zones """
|
||||
""" local API to manage system, engines and areas """
|
||||
|
||||
import re, sys, os
|
||||
import logging as log
|
||||
@@ -138,6 +138,84 @@ class Area:
|
||||
self._real_temp,
|
||||
self._order_temp))
|
||||
|
||||
class Engine:
|
||||
''' koolnova Engine class '''
|
||||
|
||||
def __init__(self,
|
||||
engine_id:int = 0,
|
||||
throughput:int = 0,
|
||||
state:const.FlowEngine = const.FlowEngine.AUTO,
|
||||
order_temp:float = 0
|
||||
) -> None:
|
||||
''' Constructor class '''
|
||||
self._engine_id = engine_id
|
||||
self._throughput = throughput
|
||||
self._state = state
|
||||
self._order_temp = order_temp
|
||||
|
||||
@property
|
||||
def engine_id(self) -> int:
|
||||
''' Get Engine ID '''
|
||||
return self._engine_id
|
||||
|
||||
@engine_id.setter
|
||||
def engine_id(self, val:int) -> None:
|
||||
''' Set Engine ID '''
|
||||
if not isinstance(val, int):
|
||||
raise AssertionError('Input variable must be Int')
|
||||
if val > const.NUM_OF_ENGINES:
|
||||
raise NumUnitError('Engine ID must be lower than {}'.format(const.NUM_OF_ENGINES))
|
||||
self._engine_id = val
|
||||
|
||||
@property
|
||||
def throughput(self) -> int:
|
||||
''' Get throughput Engine '''
|
||||
return self._throughput
|
||||
|
||||
@throughput.setter
|
||||
def throughput(self, val:int) -> None:
|
||||
''' Set throughput Engine '''
|
||||
if not isinstance(val, int):
|
||||
raise AssertionError('Input variable must be Int')
|
||||
if val > const.FLOW_ENGINE_VAL_MAX or val < const.FLOW_ENGINE_VAL_MIN:
|
||||
raise FlowEngineError('throughput engine value ({}) must be between {} and {}'.format(val,
|
||||
const.FLOW_ENGINE_VAL_MIN,
|
||||
const.FLOW_ENGINE_VAL_MAX))
|
||||
self._throughput = val
|
||||
|
||||
@property
|
||||
def state(self) -> const.FlowEngine:
|
||||
''' Get Engine state '''
|
||||
return self._state
|
||||
|
||||
@state.setter
|
||||
def state(self, val:const.FlowEngine) -> None:
|
||||
''' Set Engine state '''
|
||||
if not isinstance(val, const.FlowEngine):
|
||||
raise AssertionError('Input variable must be Enum FlowEngine')
|
||||
self._state = val
|
||||
|
||||
@property
|
||||
def order_temp(self) -> float:
|
||||
''' Get Order Temp '''
|
||||
return self._order_temp
|
||||
|
||||
@order_temp.setter
|
||||
def order_temp(self, val:float = 0.0) -> None:
|
||||
''' Set order temp engine '''
|
||||
if not isinstance(val, float):
|
||||
raise AssertionError('Input variable must be Int')
|
||||
if val > 0 and (val > 30.0 or val < 15.0):
|
||||
raise OrderTempError('Flow Engine value ({}) must be between 15 and 30'.format(val))
|
||||
self._order_temp = val
|
||||
|
||||
def __repr__(self) -> str:
|
||||
''' repr method '''
|
||||
return repr('Unit(Id:{}, Throughput:{}, State:{}, Order Temp:{})'.format(self._engine_id,
|
||||
self._throughput,
|
||||
self._state,
|
||||
self._order_temp))
|
||||
|
||||
class Koolnova:
|
||||
''' koolnova Device class '''
|
||||
|
||||
@@ -162,7 +240,7 @@ class Koolnova:
|
||||
self._global_mode = const.GlobalMode.COLD
|
||||
self._efficiency = const.Efficiency.LOWER_EFF
|
||||
self._sys_state = const.SysState.SYS_STATE_OFF
|
||||
self._units = []
|
||||
self._engines = []
|
||||
self._areas = []
|
||||
|
||||
def _area_defined(self,
|
||||
@@ -202,18 +280,17 @@ class Koolnova:
|
||||
_LOGGER.error("Error retreiving efficiency")
|
||||
self._efficiency = const.Efficiency.LOWER_EFF
|
||||
|
||||
#await asyncio.sleep(0.1)
|
||||
await asyncio.sleep(0.1)
|
||||
|
||||
#_LOGGER.debug("Retreive units ...")
|
||||
#for idx in range(1, const.NUM_OF_ENGINES + 1):
|
||||
# _LOGGER.debug("Unit id: {}".format(idx))
|
||||
# unit = Unit(unit_id = idx)
|
||||
# ret, unit.flow_engine = await self._client.flow_engine(unit_id = idx)
|
||||
# ret, unit.flow_state = await self._client.flow_state_engine(unit_id = idx)
|
||||
# ret, unit.order_temp = await self._client.order_temp_engine(unit_id = idx)
|
||||
# self._units.append(unit)
|
||||
# await asyncio.sleep(0.1)
|
||||
|
||||
_LOGGER.debug("Retreive engines ...")
|
||||
for idx in range(1, const.NUM_OF_ENGINES + 1):
|
||||
_LOGGER.debug("Engine id: {}".format(idx))
|
||||
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)
|
||||
self._engines.append(engine)
|
||||
await asyncio.sleep(0.1)
|
||||
return True
|
||||
|
||||
async def connect(self) -> bool:
|
||||
@@ -329,9 +406,10 @@ class Koolnova:
|
||||
|
||||
return self._areas
|
||||
|
||||
def get_units(self) -> list:
|
||||
''' get units '''
|
||||
return self._units
|
||||
@property
|
||||
def engines(self) -> list:
|
||||
''' get engines '''
|
||||
return self._engines
|
||||
|
||||
@property
|
||||
def device_info(self) -> DeviceInfo:
|
||||
@@ -512,84 +590,6 @@ class Koolnova:
|
||||
self._efficiency,
|
||||
self._sys_state))
|
||||
|
||||
class Unit:
|
||||
''' koolnova Unit class '''
|
||||
|
||||
def __init__(self,
|
||||
unit_id:int = 0,
|
||||
flow_engine:int = 0,
|
||||
flow_state:const.FlowEngine = const.FlowEngine.AUTO,
|
||||
order_temp:float = 0
|
||||
) -> None:
|
||||
''' Constructor class '''
|
||||
self._unit_id = unit_id
|
||||
self._flow_engine = flow_engine
|
||||
self._flow_state = flow_state
|
||||
self._order_temp = order_temp
|
||||
|
||||
@property
|
||||
def unit_id(self) -> int:
|
||||
''' Get Unit ID '''
|
||||
return self._unit_id
|
||||
|
||||
@unit_id.setter
|
||||
def unit_id(self, val:int) -> None:
|
||||
''' Set Unit ID '''
|
||||
if not isinstance(val, int):
|
||||
raise AssertionError('Input variable must be Int')
|
||||
if val > const.NUM_OF_ENGINES:
|
||||
raise NumUnitError('Unit ID must be lower than {}'.format(const.NUM_OF_ENGINES))
|
||||
self._unit_id = val
|
||||
|
||||
@property
|
||||
def flow_engine(self) -> int:
|
||||
''' Get Flow Engine '''
|
||||
return self._flow_engine
|
||||
|
||||
@flow_engine.setter
|
||||
def flow_engine(self, val:int) -> None:
|
||||
''' Set Flow Engine '''
|
||||
if not isinstance(val, int):
|
||||
raise AssertionError('Input variable must be Int')
|
||||
if val > const.FLOW_ENGINE_VAL_MAX or val < const.FLOW_ENGINE_VAL_MIN:
|
||||
raise FlowEngineError('Flow Engine value ({}) must be between {} and {}'.format(val,
|
||||
const.FLOW_ENGINE_VAL_MIN,
|
||||
const.FLOW_ENGINE_VAL_MAX))
|
||||
self._flow_engine = val
|
||||
|
||||
@property
|
||||
def flow_state(self) -> const.FlowEngine:
|
||||
''' Get Flow State '''
|
||||
return self._flow_state
|
||||
|
||||
@flow_state.setter
|
||||
def flow_state(self, val:const.FlowEngine) -> None:
|
||||
''' Set Flow State '''
|
||||
if not isinstance(val, const.FlowEngine):
|
||||
raise AssertionError('Input variable must be Enum FlowEngine')
|
||||
self._flow_state = val
|
||||
|
||||
@property
|
||||
def order_temp(self) -> float:
|
||||
''' Get Order Temp '''
|
||||
return self._order_temp
|
||||
|
||||
@order_temp.setter
|
||||
def order_temp(self, val:float = 0.0) -> None:
|
||||
''' Set Flow Engine '''
|
||||
if not isinstance(val, float):
|
||||
raise AssertionError('Input variable must be Int')
|
||||
if val > 0 and (val > 30.0 or val < 15.0):
|
||||
raise OrderTempError('Flow Engine value ({}) must be between 15 and 30'.format(val))
|
||||
self._flow_engine = val
|
||||
|
||||
def __repr__(self) -> str:
|
||||
''' repr method '''
|
||||
return repr('Unit(Id:{}, Flow Engine:{}, Flow State:{}, Order Temp:{})'.format(self._unit_id,
|
||||
self._flow_engine,
|
||||
self._flow_state,
|
||||
self._order_temp))
|
||||
|
||||
class NumUnitError(Exception):
|
||||
''' user defined exception '''
|
||||
|
||||
|
||||
@@ -197,6 +197,7 @@ class Operations:
|
||||
async def areas_registered(self) -> (bool, dict):
|
||||
""" Get all areas values """
|
||||
_areas_dict:dict = {}
|
||||
# retreive all areas (registered and unregistered)
|
||||
regs, ret = await self.__read_registers(start_reg = const.REG_START_ZONE,
|
||||
count = const.NUM_REG_PER_ZONE * const.NB_ZONE_MAX)
|
||||
if not ret:
|
||||
@@ -204,6 +205,7 @@ class Operations:
|
||||
for area_idx in range(const.NB_ZONE_MAX):
|
||||
_idx:int = 4 * area_idx
|
||||
_area_dict:dict = {}
|
||||
# test if area is registered or not
|
||||
if const.ZoneRegister(regs[_idx + const.REG_LOCK_ZONE] >> 1) == const.ZoneRegister.REGISTER_OFF:
|
||||
continue
|
||||
|
||||
@@ -267,8 +269,8 @@ class Operations:
|
||||
_LOGGER.error('Error writing efficiency')
|
||||
return ret
|
||||
|
||||
async def flow_engines(self) -> (bool, list):
|
||||
''' read flow engines AC1, AC2, AC3, AC4 '''
|
||||
async def engines_throughput(self) -> (bool, list):
|
||||
''' read engines throughput AC1, AC2, AC3, AC4 '''
|
||||
engines_lst = []
|
||||
regs, ret = await self.__read_registers(const.REG_START_FLOW_ENGINE,
|
||||
const.NUM_OF_ENGINES)
|
||||
@@ -276,52 +278,52 @@ class Operations:
|
||||
for idx, reg in enumerate(regs):
|
||||
engines_lst.append(const.FlowEngine(reg))
|
||||
else:
|
||||
_LOGGER.error('Error retreive flow engines')
|
||||
_LOGGER.error('Error retreive engines throughput')
|
||||
return ret, engines_lst
|
||||
|
||||
async def flow_engine(self,
|
||||
unit_id:int = 0,
|
||||
) -> (bool, int):
|
||||
''' read flow unit specified by unit id '''
|
||||
if unit_id < 1 or unit_id > 4:
|
||||
raise UnitIdError("Unit Id must be between 1 and 4")
|
||||
reg, ret = await self.__read_register(const.REG_START_FLOW_ENGINE + (unit_id - 1))
|
||||
async def 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")
|
||||
reg, ret = await self.__read_register(const.REG_START_FLOW_ENGINE + (engine_id - 1))
|
||||
if not ret:
|
||||
_LOGGER.error('Error retreive flow engine for id:{}'.format(unit_id))
|
||||
_LOGGER.error('Error retreive engine throughput for id:{}'.format(engine_id))
|
||||
reg = 0
|
||||
return ret, reg
|
||||
|
||||
async def flow_state_engine(self,
|
||||
unit_id:int = 0,
|
||||
) -> (bool, const.FlowEngine):
|
||||
if unit_id < 1 or unit_id > 4:
|
||||
raise UnitIdError("Unit Id must be between 1 and 4")
|
||||
reg, ret = await self.__read_register(const.REG_START_FLOW_STATE_ENGINE + (unit_id - 1))
|
||||
async def engine_state(self,
|
||||
engine_id:int = 0,
|
||||
) -> (bool, const.FlowEngine):
|
||||
if engine_id < 1 or engine_id > 4:
|
||||
raise UnitIdError("Engine id must be between 1 and 4")
|
||||
reg, ret = await self.__read_register(const.REG_START_FLOW_STATE_ENGINE + (engine_id - 1))
|
||||
if not ret:
|
||||
_LOGGER.error('Error retreive flow state for id:{}'.format(unit_id))
|
||||
_LOGGER.error('Error retreive engine state for id:{}'.format(engine_id))
|
||||
reg = 0
|
||||
return ret, const.FlowEngine(reg)
|
||||
|
||||
async def order_temp_engine(self,
|
||||
unit_id:int = 0,
|
||||
async def engine_order_temp(self,
|
||||
engine_id:int = 0,
|
||||
) -> (bool, float):
|
||||
if unit_id < 1 or unit_id > 4:
|
||||
raise UnitIdError("Unit Id must be between 1 and 4")
|
||||
reg, ret = await self.__read_register(const.REG_START_ORDER_TEMP + (unit_id - 1))
|
||||
if engine_id < 1 or engine_id > 4:
|
||||
raise UnitIdError("Engine id must be between 1 and 4")
|
||||
reg, ret = await self.__read_register(const.REG_START_ORDER_TEMP + (engine_id - 1))
|
||||
if not ret:
|
||||
_LOGGER.error('Error retreive order temp for id:{}'.format(unit_id))
|
||||
_LOGGER.error('Error retreive engine order temp for id:{}'.format(engine_id))
|
||||
reg = 0
|
||||
return ret, reg / 2
|
||||
|
||||
async def orders_temp(self) -> (bool, list):
|
||||
''' read orders temperature AC1, AC2, AC3, AC4 '''
|
||||
async def engine_orders_temp(self) -> (bool, list):
|
||||
''' read orders temperature for engines : AC1, AC2, AC3, AC4 '''
|
||||
engines_lst = []
|
||||
regs, ret = await self.__read_registers(const.REG_START_ORDER_TEMP, const.NUM_OF_ENGINES)
|
||||
if ret:
|
||||
for idx, reg in enumerate(regs):
|
||||
engines_lst.append(reg/2)
|
||||
else:
|
||||
_LOGGER.error('error reading flow engines registers')
|
||||
_LOGGER.error('error reading engines order temp registers')
|
||||
return ret, engines_lst
|
||||
|
||||
async def set_area_target_temp(self,
|
||||
|
||||
Reference in new issue
Block a user