Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions custom_components/omnilogic_local/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry, async_add_e
entities.append(
OmniLogicChlorinatorSaltLevelSensorEntity(coordinator=coordinator, context=system_id, sensor_type="instant")
)
entities.append(
OmniLogicChlorinatorSaltCellSensor(coordinator=coordinator, context=system_id)
)

case ChlorinatorDispenserType.LIQUID:
# It looks like there are no liquid sensors exposed in the telemetry
pass
Expand Down Expand Up @@ -270,6 +274,34 @@ def native_value(self) -> StateType | date | datetime | Decimal:
def name(self) -> Any:
return f"{self.data.msp_config.name} {self._sensor_type.capitalize()} Salt Level"

class OmniLogicChlorinatorSaltCellSensor(OmniLogicEntity[EntityIndexChlorinator], SensorEntity):
def __init__(self, coordinator: OmniLogicCoordinator, context: int) -> None:
super().__init__(coordinator, context)

@property
def name(self) -> Any:
return f"{self.data.msp_config.name} Salt Cell Status"

@property
def native_value(self) -> StateType | date | datetime | Decimal:
is_on = (self.data.telemetry.status_raw & 0b00000100) != 0
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer that this parsing be done in the underlying library and then values be exposed to the integration from there.

is_init = (self.data.telemetry.status_raw & 0b00000010) != 0
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this bit does not indicate that the salt cell is in an initialization state, it indicates that there is an alert value present. You would then need to reference the value of chlrAlert from the telemetry to determine what alert is present.

Likewise bit 0 indicates an error is present and you would then reference chlrError from the telemetry to see what error is present.

polarity_k1 = (self.data.telemetry.status_raw & 0b01000000) != 0
polarity_k2 = (self.data.telemetry.status_raw & 0b10000000) != 0
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, I would prefer this parsing happen in the underlying library and then be exposed as attributes for the on/off sensor indicating which relay is active.


if not is_on:
return "OFF"

if not is_init:
return "Init"

if polarity_k1:
return "K1"

if polarity_k2:
return "K2"

return self.data.telemetry.status_raw

class OmniLogicCSADAcidPhEntity(OmniLogicEntity[EntityIndexCSAD], SensorEntity):
_attr_device_class = SensorDeviceClass.PH
Expand Down