Skip to content

Commit

Permalink
Merge parameters.
Browse files Browse the repository at this point in the history
Merge two separate parameters tuples into a single dictionary, keyed by product type.

While this is slightly less pythonic, it's a lot simpler to work with.

This is done to both ecomax parameters and mixer parameters.
  • Loading branch information
denpamusic committed Oct 19, 2023
1 parent f91e0d3 commit a33e3c7
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 259 deletions.
14 changes: 4 additions & 10 deletions pyplumio/devices/ecomax.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
DeviceState,
DeviceType,
FrameType,
ProductType,
)
from pyplumio.devices import Addressable
from pyplumio.devices.mixer import Mixer
Expand All @@ -40,8 +39,7 @@
ATTR_ECOMAX_CONTROL,
ATTR_ECOMAX_PARAMETERS,
ECOMAX_CONTROL_PARAMETER,
ECOMAX_I_PARAMETERS,
ECOMAX_P_PARAMETERS,
ECOMAX_PARAMETERS,
THERMOSTAT_PROFILE_PARAMETER,
EcomaxParameter,
)
Expand All @@ -50,7 +48,7 @@
from pyplumio.structures.mixer_parameters import ATTR_MIXER_PARAMETERS
from pyplumio.structures.mixer_sensors import ATTR_MIXER_SENSORS
from pyplumio.structures.network_info import ATTR_NETWORK, NetworkInfo
from pyplumio.structures.product_info import ATTR_PRODUCT
from pyplumio.structures.product_info import ATTR_PRODUCT, ProductInfo
from pyplumio.structures.regulator_data import ATTR_REGDATA, ATTR_REGDATA_DECODER
from pyplumio.structures.schedules import (
ATTR_SCHEDULE_PARAMETERS,
Expand Down Expand Up @@ -191,13 +189,9 @@ async def _handle_ecomax_parameters(
For each parameter dispatch an event with the parameter's name
and value.
"""
product = await self.get(ATTR_PRODUCT)
product: ProductInfo = await self.get(ATTR_PRODUCT)
for index, value in parameters:
description = (
ECOMAX_P_PARAMETERS[index]
if product.type == ProductType.ECOMAX_P
else ECOMAX_I_PARAMETERS[index]
)
description = ECOMAX_PARAMETERS[product.type][index]
await self.dispatch(
description.name,
description.cls(
Expand Down
18 changes: 4 additions & 14 deletions pyplumio/devices/mixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@
import asyncio
from typing import Sequence

from pyplumio.const import ProductType
from pyplumio.devices import Addressable, SubDevice
from pyplumio.helpers.typing import EventDataType, ParameterTupleType
from pyplumio.structures.mixer_parameters import (
ATTR_MIXER_PARAMETERS,
ECOMAX_I_MIXER_PARAMETERS,
ECOMAX_P_MIXER_PARAMETERS,
)
from pyplumio.structures.mixer_parameters import ATTR_MIXER_PARAMETERS, MIXER_PARAMETERS
from pyplumio.structures.mixer_sensors import ATTR_MIXER_SENSORS
from pyplumio.structures.product_info import ATTR_PRODUCT
from pyplumio.structures.product_info import ATTR_PRODUCT, ProductInfo


class Mixer(SubDevice):
Expand Down Expand Up @@ -44,14 +39,9 @@ async def _handle_parameters(
For each parameter dispatch an event with the
parameter's name and value.
"""
product = await self.parent.get(ATTR_PRODUCT)

product: ProductInfo = await self.parent.get(ATTR_PRODUCT)
for index, value in parameters:
description = (
ECOMAX_P_MIXER_PARAMETERS[index]
if product.type == ProductType.ECOMAX_P
else ECOMAX_I_MIXER_PARAMETERS[index]
)
description = MIXER_PARAMETERS[product.type][index]
await self.dispatch(
description.name,
description.cls(
Expand Down
Loading

0 comments on commit a33e3c7

Please sign in to comment.