|
@@ -59,7 +59,7 @@ class OnRatioController:
|
|
|
|
|
|
return switch
|
|
|
|
|
|
- def calculate_on_ratio(self, delta_on: float, delta_off: float, last_mode: str) -> float:
|
|
|
+ def calculate_on_ratio(self, period_time: float, delta_on: float, delta_off: float, last_mode: str) -> float:
|
|
|
if self.period_num == 0:
|
|
|
if last_mode == 'normal':
|
|
|
ratio = 0.9
|
|
@@ -75,7 +75,8 @@ class OnRatioController:
|
|
|
ratio = 0.9
|
|
|
else:
|
|
|
try:
|
|
|
- ratio = (0.5 * (self.return_air - self.target) + delta_off) / (delta_off - delta_on)
|
|
|
+ ratio = (0.5 * (self.target - self.return_air) / period_time - delta_off) / (delta_on - delta_off)
|
|
|
+ logger.debug(f'delta target: {0.5 * (self.target - self.return_air)}')
|
|
|
if ratio > 0.9:
|
|
|
ratio = 0.9
|
|
|
except ZeroDivisionError:
|
|
@@ -134,7 +135,7 @@ async def start_on_ratio_mode(device_id: str, target: float, period_time: int):
|
|
|
_DAILY_OFF_TIME = '220000'
|
|
|
|
|
|
period_num = 0
|
|
|
- last_on_ratio = 1.0
|
|
|
+ last_on_ratio = 0.9
|
|
|
last_mode = 'default'
|
|
|
life_count = 0
|
|
|
while life_count < 2000:
|
|
@@ -149,43 +150,37 @@ async def start_on_ratio_mode(device_id: str, target: float, period_time: int):
|
|
|
water_valve = controller.select_water_valve()
|
|
|
|
|
|
if mode == 'on_ratio':
|
|
|
- on_ratio = controller.calculate_on_ratio(delta_on, delta_off, last_mode)
|
|
|
+ on_ratio = controller.calculate_on_ratio(period_time, delta_on, delta_off, last_mode)
|
|
|
on_range = round_half_up(period_time * on_ratio)
|
|
|
off_range = period_time - on_range
|
|
|
logger.debug(f'life count: {life_count}, {device_id}, on time: {on_range}, off time: {off_range}, '
|
|
|
f'on ratio: {on_ratio}, delta_on: {delta_on * 900}, delta_off: {delta_off * 900}')
|
|
|
|
|
|
- if 0 < on_ratio < 1:
|
|
|
- await send_instructions(device_id, switch, speed, water_valve)
|
|
|
- logger.debug(f'{device_id}, {switch}, {speed}, {water_valve}')
|
|
|
- await asyncio.sleep(on_range)
|
|
|
- await send_instructions(device_id, switch, speed, False)
|
|
|
- logger.debug(f'{device_id}, {switch}, {speed}, off')
|
|
|
- await asyncio.sleep(off_range)
|
|
|
- else:
|
|
|
- await send_instructions(device_id, switch, speed, water_valve)
|
|
|
- logger.debug(f'{device_id}, {switch}, {speed}, {water_valve}')
|
|
|
- await asyncio.sleep(period_time)
|
|
|
+ await send_instructions(device_id, switch, speed, water_valve)
|
|
|
+ logger.debug(f'{device_id}, {switch}, {speed}, {water_valve}')
|
|
|
+ await asyncio.sleep(on_range)
|
|
|
+ await send_instructions(device_id, switch, speed, False)
|
|
|
+ logger.debug(f'{device_id}, {switch}, {speed}, off')
|
|
|
+ await asyncio.sleep(off_range)
|
|
|
|
|
|
period_num += 1
|
|
|
last_on_ratio = on_ratio
|
|
|
last_mode = mode
|
|
|
else:
|
|
|
await send_instructions(device_id, switch, speed, water_valve)
|
|
|
- logger.debug(f'{device_id}, {switch}, {speed}, {water_valve}')
|
|
|
+ logger.debug(f'life count: {life_count}, {device_id}, {switch}, {speed}, {water_valve}')
|
|
|
await asyncio.sleep(period_time)
|
|
|
|
|
|
period_num = 0
|
|
|
- last_on_ratio = 1.0
|
|
|
+ last_on_ratio = 0.9
|
|
|
last_mode = mode
|
|
|
|
|
|
life_count += 1
|
|
|
|
|
|
- logger.info(f'{life_count}: {device_id} - {mode}')
|
|
|
else:
|
|
|
await send_instructions(device_id, False, 'off', False)
|
|
|
period_num = 0
|
|
|
- last_on_ratio = 0.0
|
|
|
+ last_on_ratio = 0.1
|
|
|
last_mode = 'off'
|
|
|
await asyncio.sleep(period_time)
|
|
|
except (KeyError, IndexError, TypeError, HTTPException):
|