Skip to content

Commit

Permalink
Support for Pure 500 and adds more entities (#116)
Browse files Browse the repository at this point in the history
* Adds support for Pure 500 and more entities

* Fix

* Fix
  • Loading branch information
JohNan authored Aug 15, 2024
1 parent b4705b9 commit df48aba
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 21 deletions.
82 changes: 64 additions & 18 deletions custom_components/wellbeing/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import logging
from enum import Enum

from homeassistant.components.binary_sensor import BinarySensorDeviceClass, BinarySensorEntity
from homeassistant.components.fan import FanEntity
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.const import UnitOfTemperature, PERCENTAGE, CONCENTRATION_PARTS_PER_MILLION, \
CONCENTRATION_PARTS_PER_BILLION, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, Platform, EntityCategory
from homeassistant.helpers.typing import UNDEFINED
Expand Down Expand Up @@ -45,12 +44,14 @@ def __init__(
name,
attr,
device_class=None,
entity_category: EntityCategory = UNDEFINED
entity_category: EntityCategory = UNDEFINED,
state_class: SensorStateClass | str | None = None
) -> None:
self.attr = attr
self.name = name
self.device_class = device_class
self.entity_category = entity_category
self.state_class = state_class
self._state = None

def setup(self, data):
Expand All @@ -68,8 +69,16 @@ def state(self):
class ApplianceSensor(ApplianceEntity):
entity_type: int = Platform.SENSOR

def __init__(self, name, attr, unit="", device_class=None, entity_category: EntityCategory = UNDEFINED) -> None:
super().__init__(name, attr, device_class, entity_category)
def __init__(
self,
name,
attr,
unit="",
device_class=None,
entity_category: EntityCategory = UNDEFINED,
state_class: SensorStateClass | str | None = None
) -> None:
super().__init__(name, attr, device_class, entity_category, state_class)
self.unit = unit


Expand All @@ -88,7 +97,7 @@ def __init__(self, name, attr, device_class=None, entity_category: EntityCategor

@property
def state(self):
return self._state in ['enabled', True, 'Connected']
return self._state in ['enabled', True, 'Connected', 'on']


class Appliance:
Expand All @@ -107,6 +116,21 @@ def __init__(self, name, pnc_id, model) -> None:

@staticmethod
def _create_entities(data):
pure500_entities = [
ApplianceSensor(
name="PM2.5",
attr='PM2_5_approximate',
unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
device_class=SensorDeviceClass.PM25,
state_class=SensorStateClass.MEASUREMENT
),
ApplianceBinary(
name='UV State',
attr='UVState',
entity_category=EntityCategory.DIAGNOSTIC,
)
]

a7_entities = [
ApplianceSensor(
name=f"{FILTER_TYPE.get(data.get('FilterType_1', 0), 'Unknown filter')} Life",
Expand All @@ -126,7 +150,7 @@ def _create_entities(data):
ApplianceBinary(
name='PM Sensor State',
attr='PMSensState',
entity_category=EntityCategory.DIAGNOSTIC
entity_category=EntityCategory.DIAGNOSTIC,
)
]

Expand All @@ -140,7 +164,8 @@ def _create_entities(data):
name="CO2",
attr='CO2',
unit=CONCENTRATION_PARTS_PER_MILLION,
device_class=SensorDeviceClass.CO2
device_class=SensorDeviceClass.CO2,
state_class=SensorStateClass.MEASUREMENT
)
]

Expand All @@ -153,48 +178,61 @@ def _create_entities(data):
name="Temperature",
attr='Temp',
unit=UnitOfTemperature.CELSIUS,
device_class=SensorDeviceClass.TEMPERATURE
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT
),
ApplianceSensor(
name="TVOC",
attr='TVOC',
unit=CONCENTRATION_PARTS_PER_BILLION
unit=CONCENTRATION_PARTS_PER_BILLION,
state_class=SensorStateClass.MEASUREMENT
),
ApplianceSensor(
name="eCO2",
attr='ECO2',
unit=CONCENTRATION_PARTS_PER_MILLION,
device_class=SensorDeviceClass.CO2
device_class=SensorDeviceClass.CO2,
state_class=SensorStateClass.MEASUREMENT
),
ApplianceSensor(
name="PM1",
attr='PM1',
unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
device_class=SensorDeviceClass.PM1
device_class=SensorDeviceClass.PM1,
state_class=SensorStateClass.MEASUREMENT
),
ApplianceSensor(
name="PM2.5",
attr='PM2_5',
unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
device_class=SensorDeviceClass.PM25
device_class=SensorDeviceClass.PM25,
state_class=SensorStateClass.MEASUREMENT
),
ApplianceSensor(
name="PM10",
attr='PM10',
unit=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
device_class=SensorDeviceClass.PM10
device_class=SensorDeviceClass.PM10,
state_class=SensorStateClass.MEASUREMENT
),
ApplianceSensor(
name="Humidity",
attr='Humidity',
unit=PERCENTAGE,
device_class=SensorDeviceClass.HUMIDITY
device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT
),
ApplianceSensor(
name="Mode",
attr='Workmode',
device_class=SensorDeviceClass.ENUM
),
ApplianceSensor(
name="Signal Strength",
attr='SignalStrength',
device_class=SensorDeviceClass.ENUM,
entity_category=EntityCategory.DIAGNOSTIC
),
ApplianceBinary(
name="Ionizer",
attr='Ionizer'
Expand All @@ -203,6 +241,12 @@ def _create_entities(data):
name="UI Light",
attr='UILight'
),
ApplianceBinary(
name="Door Open",
attr='DoorOpen',
device_class=BinarySensorDeviceClass.DOOR,
entity_category=EntityCategory.DIAGNOSTIC
),
ApplianceBinary(
name="Connection State",
attr='connectionState',
Expand All @@ -221,7 +265,7 @@ def _create_entities(data):
)
]

return common_entities + a9_entities + a7_entities
return common_entities + a9_entities + a7_entities + pure500_entities

def get_entity(self, entity_type, entity_attr):
return next(
Expand All @@ -246,8 +290,10 @@ def setup(self, data, capabilities):
]

@property
def speed_range(self) -> tuple[float, float]:
def speed_range(self) -> tuple[int, int]:
## Electrolux Devices:
if self.model == "Muju":
return 1, 3
if self.model == "WELLA5":
return 1, 5
if self.model == "WELLA7":
Expand Down
3 changes: 1 addition & 2 deletions custom_components/wellbeing/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ def __init__(self, coordinator: WellbeingDataUpdateCoordinator, config_entry, pn
super().__init__(coordinator, config_entry, pnc_id, entity_type, entity_attr)
self._preset_mode = str(self.get_appliance.mode)
self._speed = self.get_entity.state
self.supported_features

@property
def _speed_range(self) -> tuple[float, float]:
def _speed_range(self) -> tuple[int, int]:
return self.get_appliance.speed_range

@property
Expand Down
6 changes: 5 additions & 1 deletion custom_components/wellbeing/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from sys import platform
from typing import cast

from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor import SensorEntity, SensorStateClass
from homeassistant.const import Platform

from .api import ApplianceSensor
Expand Down Expand Up @@ -36,3 +36,7 @@ def native_value(self):
@property
def native_unit_of_measurement(self):
return cast(ApplianceSensor, self.get_entity).unit

@property
def state_class(self) -> SensorStateClass | str | None:
return self.get_entity.state_class

0 comments on commit df48aba

Please sign in to comment.