Skip to content

Commit

Permalink
Improve descriptors.
Browse files Browse the repository at this point in the history
Use multiply instead of division to calculate a display value to avoid unnecessary float conversion.
  • Loading branch information
denpamusic committed Nov 3, 2023
1 parent 4a932b2 commit 05b983e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 37 deletions.
25 changes: 12 additions & 13 deletions pyplumio/structures/ecomax_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,24 @@ class EcomaxParameter(Parameter):
async def set(self, value: ParameterValueType, retries: int = 5) -> bool:
"""Set a parameter value."""
if isinstance(value, (int, float)):
value *= self.description.multiplier
value -= self.description.offset
value = int((value + self.description.offset) / self.description.multiplier)

return await super().set(value, retries)

@property
def value(self) -> ParameterValueType:
"""A parameter value."""
return (self._value + self.description.offset) / self.description.multiplier
return (self._value - self.description.offset) * self.description.multiplier

@property
def min_value(self) -> ParameterValueType:
"""Minimum allowed value."""
return (self._min_value + self.description.offset) / self.description.multiplier
return (self._min_value - self.description.offset) * self.description.multiplier

@property
def max_value(self) -> ParameterValueType:
"""Maximum allowed value."""
return (self._max_value + self.description.offset) / self.description.multiplier
return (self._max_value - self.description.offset) * self.description.multiplier

@property
def request(self) -> Request:
Expand Down Expand Up @@ -99,7 +98,7 @@ class EcomaxBinaryParameter(BinaryParameter, EcomaxParameter):
class EcomaxParameterDescription(ParameterDescription):
"""Represents an ecoMAX parameter description."""

multiplier: int = 1
multiplier: float = 1
offset: int = 0


Expand Down Expand Up @@ -197,10 +196,10 @@ class EcomaxBinaryParameterDescription(
EcomaxParameterDescription(name="oxygen_50"),
EcomaxParameterDescription(name="oxygen_30"),
EcomaxParameterDescription(name="oxygen_correction_fl"),
EcomaxParameterDescription(name="fuel_flow_kg_h", multiplier=10),
EcomaxParameterDescription(name="fuel_flow_kg_h", multiplier=0.1),
EcomaxParameterDescription(name="feeder_calibration"),
EcomaxParameterDescription(name="fuel_factor"),
EcomaxParameterDescription(name="fuel_calorific_value_kwh_kg", multiplier=10),
EcomaxParameterDescription(name="fuel_calorific_value_kwh_kg", multiplier=0.1),
EcomaxParameterDescription(name="fuel_detection_time"),
EcomaxParameterDescription(name="fuel_detection_fumes_temp"),
EcomaxParameterDescription(name="schedule_feeder_2"),
Expand All @@ -219,8 +218,8 @@ class EcomaxBinaryParameterDescription(
EcomaxParameterDescription(name="work_term"),
EcomaxParameterDescription(name="increase_heating_temp_for_water_heater"),
EcomaxBinaryParameterDescription(name="heating_weather_control"),
EcomaxParameterDescription(name="heating_heat_curve", multiplier=10),
EcomaxParameterDescription(name="heating_heat_curve_shift", offset=-20),
EcomaxParameterDescription(name="heating_heat_curve", multiplier=0.1),
EcomaxParameterDescription(name="heating_heat_curve_shift", offset=20),
EcomaxParameterDescription(name="weather_factor"),
EcomaxParameterDescription(name="term_boiler_operation"),
EcomaxBinaryParameterDescription(name="term_boiler_mode"),
Expand Down Expand Up @@ -263,8 +262,8 @@ class EcomaxBinaryParameterDescription(
EcomaxBinaryParameterDescription(name="water_heater_disinfection"),
EcomaxParameterDescription(name="water_heater_work_mode"),
EcomaxBinaryParameterDescription(name="solar_support"),
EcomaxParameterDescription(name="solar_pump_on_delta_temp", multiplier=10),
EcomaxParameterDescription(name="solar_pump_off_delta_temp", multiplier=10),
EcomaxParameterDescription(name="solar_pump_on_delta_temp", multiplier=0.1),
EcomaxParameterDescription(name="solar_pump_off_delta_temp", multiplier=0.1),
EcomaxParameterDescription(name="min_collector_temp"),
EcomaxParameterDescription(name="max_collector_temp"),
EcomaxParameterDescription(name="collector_off_temp"),
Expand All @@ -290,7 +289,7 @@ class EcomaxBinaryParameterDescription(
EcomaxParameterDescription(name="circuit_work_time"),
EcomaxParameterDescription(name="alarm_out_c"),
EcomaxParameterDescription(name="alarm_on_out_c"),
EcomaxParameterDescription(name="thermostat_hysteresis", multiplier=10),
EcomaxParameterDescription(name="thermostat_hysteresis", multiplier=0.1),
EcomaxParameterDescription(name="critial_additional_heat_source_temp"),
EcomaxParameterDescription(name="automatic_pump_lock_time"),
EcomaxParameterDescription(name="summer_mode"),
Expand Down
21 changes: 10 additions & 11 deletions pyplumio/structures/mixer_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,24 @@ class MixerParameter(Parameter):
async def set(self, value: ParameterValueType, retries: int = 5) -> bool:
"""Set a parameter value."""
if isinstance(value, (int, float)):
value *= self.description.multiplier
value -= self.description.offset
value = int((value + self.description.offset) / self.description.multiplier)

return await super().set(value, retries)

@property
def value(self) -> ParameterValueType:
"""A parameter value."""
return (self._value / self.description.multiplier) - self.description.offset
return (self._value - self.description.offset) * self.description.multiplier

@property
def min_value(self) -> ParameterValueType:
"""Minimum allowed value."""
return (self._min_value / self.description.multiplier) - self.description.offset
return (self._min_value - self.description.offset) * self.description.multiplier

@property
def max_value(self) -> ParameterValueType:
"""Maximum allowed value."""
return (self._max_value / self.description.multiplier) - self.description.offset
return (self._max_value - self.description.offset) * self.description.multiplier

@property
def request(self) -> Request:
Expand All @@ -78,7 +77,7 @@ class MixerBinaryParameter(BinaryParameter, MixerParameter):
class MixerParameterDescription(ParameterDescription):
"""Represents a mixer parameter description."""

multiplier: int = 1
multiplier: float = 1
offset: int = 0


Expand All @@ -96,11 +95,11 @@ class MixerBinaryParameterDescription(
MixerParameterDescription(name="max_target_temp"),
MixerParameterDescription(name="low_target_temp"),
MixerBinaryParameterDescription(name="weather_control"),
MixerParameterDescription(name="heating_curve", multiplier=10),
MixerParameterDescription(name="heating_curve_shift", offset=-20),
MixerParameterDescription(name="heating_curve", multiplier=0.1),
MixerParameterDescription(name="heating_curve_shift", offset=20),
MixerParameterDescription(name="weather_temp_factor"),
MixerParameterDescription(name="work_mode"),
MixerParameterDescription(name="insensitivity", multiplier=10),
MixerParameterDescription(name="insensitivity", multiplier=0.1),
MixerParameterDescription(name="thermostat_operation"),
MixerParameterDescription(name="thermostat_mode"),
MixerBinaryParameterDescription(name="off_therm_pump"),
Expand All @@ -121,10 +120,10 @@ class MixerBinaryParameterDescription(
MixerParameterDescription(name="thermostat_correction"),
MixerBinaryParameterDescription(name="thermostat_pump_lock"),
MixerParameterDescription(name="valve_full_opening_time"),
MixerParameterDescription(name="mixer_dead_zone", multiplier=10),
MixerParameterDescription(name="mixer_dead_zone", multiplier=0.1),
MixerParameterDescription(name="proportional_range"),
MixerParameterDescription(name="integration_time_constant"),
MixerParameterDescription(name="heating_curve", multiplier=10),
MixerParameterDescription(name="heating_curve", multiplier=0.1),
MixerParameterDescription(name="heating_curve_shift", offset=20),
MixerParameterDescription(name="thermostat_function"),
MixerParameterDescription(name="decreasing_constant_water_temp"),
Expand Down
26 changes: 13 additions & 13 deletions pyplumio/structures/thermostat_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ def __init__(self, offset: int, *args, **kwargs):
async def set(self, value: ParameterValueType, retries: int = 5) -> bool:
"""Set a parameter value."""
if isinstance(value, (int, float)):
value *= self.description.multiplier
value = int(value / self.description.multiplier)

return await super().set(int(value), retries)
return await super().set(value, retries)

@property
def value(self) -> ParameterValueType:
"""A parameter value."""
return self._value / self.description.multiplier
return self._value * self.description.multiplier

@property
def min_value(self) -> ParameterValueType:
"""Minimum allowed value."""
return self._min_value / self.description.multiplier
return self._min_value * self.description.multiplier

@property
def max_value(self) -> ParameterValueType:
"""Maximum allowed value."""
return self._max_value / self.description.multiplier
return self._max_value * self.description.multiplier

@property
def request(self) -> Request:
Expand All @@ -90,7 +90,7 @@ class ThermostatBinaryParameter(BinaryParameter, ThermostatParameter):
class ThermostatParameterDescription(ParameterDescription):
"""Represents a thermostat parameter description."""

multiplier: int = 1
multiplier: float = 1.0
size: int = 1


Expand All @@ -103,20 +103,20 @@ class ThermostatBinaryParameterDescription(

THERMOSTAT_PARAMETERS: tuple[ThermostatParameterDescription, ...] = (
ThermostatParameterDescription(name="mode"),
ThermostatParameterDescription(name="party_target_temp", size=2, multiplier=10),
ThermostatParameterDescription(name="holidays_target_temp", size=2, multiplier=10),
ThermostatParameterDescription(name="party_target_temp", size=2, multiplier=0.1),
ThermostatParameterDescription(name="holidays_target_temp", size=2, multiplier=0.1),
ThermostatParameterDescription(name="correction"),
ThermostatParameterDescription(name="away_timer"),
ThermostatParameterDescription(name="airing_timer"),
ThermostatParameterDescription(name="party_timer"),
ThermostatParameterDescription(name="holidays_timer"),
ThermostatParameterDescription(name="hysteresis", multiplier=10),
ThermostatParameterDescription(name="day_target_temp", size=2, multiplier=10),
ThermostatParameterDescription(name="night_target_temp", size=2, multiplier=10),
ThermostatParameterDescription(name="hysteresis", multiplier=0.1),
ThermostatParameterDescription(name="day_target_temp", size=2, multiplier=0.1),
ThermostatParameterDescription(name="night_target_temp", size=2, multiplier=0.1),
ThermostatParameterDescription(
name="antifreeze_target_temp", size=2, multiplier=10
name="antifreeze_target_temp", size=2, multiplier=0.1
),
ThermostatParameterDescription(name="heating_target_temp", size=2, multiplier=10),
ThermostatParameterDescription(name="heating_target_temp", size=2, multiplier=0.1),
ThermostatParameterDescription(name="heating_timer"),
ThermostatParameterDescription(name="off_timer"),
)
Expand Down

0 comments on commit 05b983e

Please sign in to comment.