Skip to content

Commit

Permalink
fix: non-aws fan auto switch
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlb committed Jan 4, 2025
1 parent 44c8610 commit f4c2a60
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def germ_shield(self) -> bool:

@property
def fan_auto_mode(self) -> bool | None | NotImplemented:
if self.model not in ["classic_680i"]:
return NotImplemented
return self.blueair_api_device.fan_auto_mode

@property
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ha_blueair/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/dahlb/ha_blueair/issues",
"loggers": ["ha_blueair", "blueair_api"],
"requirements": ["blueair-api==1.30.1"],
"requirements": ["blueair-api==1.30.2"],
"version": "1.23.0"
}
138 changes: 37 additions & 101 deletions custom_components/ha_blueair/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from homeassistant.components.switch import (
SwitchEntity,
SwitchDeviceClass,
SwitchDeviceClass, SwitchEntityDescription,
)

from .entity import BlueairEntity, async_setup_entry_helper
Expand All @@ -23,126 +23,62 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
])


class BlueairChildLockSwitchEntity(BlueairEntity, SwitchEntity):
_attr_device_class = SwitchDeviceClass.SWITCH

@classmethod
def is_implemented(kls, coordinator):
return coordinator.child_lock is not NotImplemented

def __init__(self, coordinator):
super().__init__("Child Lock", coordinator)

@property
def is_on(self) -> bool | None:
return self.coordinator.child_lock

async def async_turn_on(self, **kwargs):
await self.coordinator.set_child_lock(True)
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
await self.coordinator.set_child_lock(False)
self.async_write_ha_state()


class BlueairGermShieldSwitchEntity(BlueairEntity, SwitchEntity):
_attr_device_class = SwitchDeviceClass.SWITCH

class BlueairSwitchEntity(BlueairEntity, SwitchEntity):
@classmethod
def is_implemented(kls, coordinator):
return coordinator.germ_shield is not NotImplemented
return getattr(coordinator, kls(coordinator).entity_description.key) is not NotImplemented

def __init__(self, coordinator):
super().__init__("Germ Shield", coordinator)
super().__init__(self.entity_description.name, coordinator)

@property
def is_on(self) -> bool | None:
return self.coordinator.germ_shield
return getattr(self.coordinator, self.entity_description.key)

async def async_turn_on(self, **kwargs):
await self.coordinator.set_germ_shield(True)
await getattr(self.coordinator, f"set_{self.entity_description.key}")(True)
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
await self.coordinator.set_germ_shield(False)
await getattr(self.coordinator, f"set_{self.entity_description.key}")(False)
self.async_write_ha_state()


class BlueairAutoFanModeSwitchEntity(BlueairEntity, SwitchEntity):
_attr_device_class = SwitchDeviceClass.SWITCH
class BlueairChildLockSwitchEntity(BlueairSwitchEntity):
entity_description = SwitchEntityDescription(
key="child_lock",
name="Child Lock",
device_class=SwitchDeviceClass.SWITCH,
)

@classmethod
def is_implemented(kls, coordinator):
return coordinator.fan_auto_mode is not NotImplemented

def __init__(self, coordinator):
super().__init__("Auto Fan Mode", coordinator)
class BlueairGermShieldSwitchEntity(BlueairSwitchEntity):
entity_description = SwitchEntityDescription(
key="germ_shield",
name="Germ Shield",
device_class=SwitchDeviceClass.SWITCH,
)

@property
def is_on(self) -> bool | None:
return self.coordinator.fan_auto_mode

async def async_turn_on(self, **kwargs):
await self.coordinator.set_fan_auto_mode(True)
self.async_write_ha_state()
class BlueairAutoFanModeSwitchEntity(BlueairSwitchEntity):
entity_description = SwitchEntityDescription(
key="fan_auto_mode",
name="Auto Fan Mode",
device_class=SwitchDeviceClass.SWITCH,
)

async def async_turn_off(self, **kwargs):
await self.coordinator.set_fan_auto_mode(False)
self.async_write_ha_state()

class BlueairNightModeSwitchEntity(BlueairSwitchEntity):
entity_description = SwitchEntityDescription(
key="night_mode",
name="Night Mode",
device_class=SwitchDeviceClass.SWITCH,
)

class BlueairNightModeSwitchEntity(BlueairEntity, SwitchEntity):
_attr_device_class = SwitchDeviceClass.SWITCH

@classmethod
def is_implemented(kls, coordinator):
return coordinator.night_mode is not NotImplemented

def __init__(self, coordinator):
super().__init__("Night Mode", coordinator)

@property
def is_on(self) -> bool | None:
return self.coordinator.night_mode

@property
def available(self) -> bool:
"""Return True if entity is available."""
return self.coordinator.night_mode is not None

async def async_turn_on(self, **kwargs):
await self.coordinator.set_night_mode(True)
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
await self.coordinator.set_night_mode(False)
self.async_write_ha_state()


class BlueairWickDryModeSwitchEntity(BlueairEntity, SwitchEntity):
_attr_device_class = SwitchDeviceClass.SWITCH

@classmethod
def is_implemented(kls, coordinator):
return coordinator.wick_dry_mode is not NotImplemented

def __init__(self, coordinator):
super().__init__("Wick Dry Mode", coordinator)

@property
def is_on(self) -> bool | None:
return self.coordinator.wick_dry_mode

@property
def available(self) -> bool:
"""Return True if entity is available."""
return self.coordinator.wick_dry_mode is not None

async def async_turn_on(self, **kwargs):
await self.coordinator.set_wick_dry_mode(True)
self.async_write_ha_state()

async def async_turn_off(self, **kwargs):
await self.coordinator.set_wick_dry_mode(False)
self.async_write_ha_state()
class BlueairWickDryModeSwitchEntity(BlueairSwitchEntity):
entity_description = SwitchEntityDescription(
key="wick_dry_mode",
name="Wick Dry Mode",
device_class=SwitchDeviceClass.SWITCH,
)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
homeassistant==2024.8.0
ruff==0.8.4
blueair-api==1.30.1
blueair-api==1.30.2

0 comments on commit f4c2a60

Please sign in to comment.