Skip to content

Commit

Permalink
Add support for Hydrojet_Pro
Browse files Browse the repository at this point in the history
  • Loading branch information
thecadams committed Feb 19, 2024
1 parent b675324 commit 2622958
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5 deletions.
3 changes: 3 additions & 0 deletions custom_components/bestway/bestway/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BestwayDeviceType(Enum):
AIRJET_SPA = "Airjet"
AIRJET_V01_SPA = "Airjet V01"
HYDROJET_SPA = "Hydrojet"
HYDROJET_PRO = "Hydrojet Pro"
POOL_FILTER = "Pool Filter"
UNKNOWN = "Unknown"

Expand All @@ -30,6 +31,8 @@ def from_api_product_name(product_name: str) -> BestwayDeviceType:
return BestwayDeviceType.AIRJET_V01_SPA
if product_name == "Hydrojet":
return BestwayDeviceType.HYDROJET_SPA
if product_name == "Hydrojet_Pro":
return BestwayDeviceType.HYDROJET_PRO
if product_name == "泳池过滤器":
# Chinese translates to "pool filter"
return BestwayDeviceType.POOL_FILTER
Expand Down
63 changes: 60 additions & 3 deletions custom_components/bestway/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,19 @@ async def async_setup_entry(
]
)

if device.device_type == BestwayDeviceType.HYDROJET_SPA:
if device.device_type in [
BestwayDeviceType.HYDROJET_SPA,
BestwayDeviceType.HYDROJET_PRO,
]:
entities.extend(
[
DeviceConnectivitySensor(
coordinator,
config_entry,
device_id,
_SPA_CONNECTIVITY_SENSOR_DESCRIPTION,
)
),
HydrojetSpaErrorsSensor(coordinator, config_entry, device_id),
]
)

Expand Down Expand Up @@ -152,7 +156,7 @@ def available(self) -> bool:


class AirjetSpaErrorsSensor(BestwayEntity, BinarySensorEntity):
"""Sensor to indicate an error state for a spa."""
"""Sensor to indicate an error state for an Airjet spa."""

def __init__(
self,
Expand Down Expand Up @@ -203,6 +207,59 @@ def extra_state_attributes(self) -> Mapping[str, Any] | None:
}


class HydrojetSpaErrorsSensor(BestwayEntity, BinarySensorEntity):
"""Sensor to indicate an error state for a Hydrojet spa."""

def __init__(
self,
coordinator: BestwayUpdateCoordinator,
config_entry: ConfigEntry,
device_id: str,
) -> None:
"""Initialize sensor."""
self.entity_description = _AIRJET_SPA_ERRORS_SENSOR_DESCRIPTION
self._attr_entity_category = EntityCategory.DIAGNOSTIC
self._attr_unique_id = f"{device_id}_{self.entity_description.key}"
super().__init__(
coordinator,
config_entry,
device_id,
)

@property
def is_on(self) -> bool | None:
"""Return true if the spa is reporting an error."""
if not self.status:
return None

errors = []
for err_num in [1,2,3,4,5,8,9,12,13]:
if self.status.attrs[f"E{str(err_num).zfill(2)}"] == 1:
errors.append(err_num)

return len(errors) > 0 or self.status.attrs.get("earth")

@property
def extra_state_attributes(self) -> Mapping[str, Any] | None:
"""Return more detailed error information."""
if not self.status:
return None

# Only return errors listed in the instruction manual.
return {
"e01": self.status.attrs["E01"],
"e02": self.status.attrs["E02"],
"e03": self.status.attrs["E03"],
"e04": self.status.attrs["E04"],
"e05": self.status.attrs["E05"],
"e08": self.status.attrs["E08"],
"e09": self.status.attrs["E09"],
"e12": self.status.attrs["E12"],
"e13": self.status.attrs["E13"],
"gcf": self.status.attrs.get("earth"), # not always present
}


class PoolFilterChangeRequiredSensor(BestwayEntity, BinarySensorEntity):
"""Sensor to indicate whether a pool filter requires a change."""

Expand Down
1 change: 1 addition & 0 deletions custom_components/bestway/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ async def async_setup_entry(
if device.device_type in [
BestwayDeviceType.AIRJET_V01_SPA,
BestwayDeviceType.HYDROJET_SPA,
BestwayDeviceType.HYDROJET_PRO,
]:
entities.append(
AirjetV01HydrojetSpaThermostat(coordinator, config_entry, device_id)
Expand Down
5 changes: 4 additions & 1 deletion custom_components/bestway/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ async def async_setup_entry(
)
)

if device.device_type == BestwayDeviceType.HYDROJET_SPA:
if device.device_type in [
BestwayDeviceType.HYDROJET_SPA,
BestwayDeviceType.HYDROJET_PRO,
]:
entities.append(
ThreeWaySpaBubblesSelect(
coordinator,
Expand Down
1 change: 1 addition & 0 deletions custom_components/bestway/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ async def async_setup_entry(
if device_info.device_type in [
BestwayDeviceType.AIRJET_SPA,
BestwayDeviceType.HYDROJET_SPA,
BestwayDeviceType.HYDROJET_PRO,
]:
name_prefix = "Spa"
elif device_info.device_type == BestwayDeviceType.POOL_FILTER:
Expand Down
5 changes: 4 additions & 1 deletion custom_components/bestway/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ async def async_setup_entry(
]
)

if device.device_type == BestwayDeviceType.HYDROJET_SPA:
if device.device_type in [
BestwayDeviceType.HYDROJET_SPA,
BestwayDeviceType.HYDROJET_PRO,
]:
entities.extend(
[
BestwaySwitch(
Expand Down

0 comments on commit 2622958

Please sign in to comment.