Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldt80 authored Apr 14, 2021
1 parent 5dbfbf7 commit f0e2bd6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
9 changes: 3 additions & 6 deletions custom_components/philips_airpurifier_http/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@
PHILIPS_SPEED_SILENT = "s"
PHILIPS_SPEED_TURBO = "t"
PHILIPS_MODE_AUTO = "P"
PHILIPS_MODE_ALLERGEN = "A"
PHILIPS_MODE_SLEEP = "S"
PHILIPS_MODE_MANUAL = "M"
PHILIPS_MODE_ALLERGEN = "A"
PHILIPS_MODE_SLEEP = "M"
PHILIPS_MODE_BACTERIA = "B"
PHILIPS_MODE_NIGH = "N"
PHILIPS_FUNCTION_PURIFICATION = "P"
PHILIPS_FUNCTION_BOTH = "PH"

Expand Down Expand Up @@ -117,11 +115,10 @@
PHILIPS_MODE_AUTO: MODE_AUTO,
PHILIPS_MODE_ALLERGEN: MODE_ALLERGEN,
PHILIPS_MODE_SLEEP: MODE_SLEEP,
PHILIPS_MODE_MANUAL: MODE_MANUAL,
PHILIPS_MODE_BACTERIA: MODE_BACTERIA,
PHILIPS_MODE_NIGH: MODE_NIGHT,
}


# Function values
FUNCTION_PURIFICATION = "Purification"
FUNCTION_BOTH = "Purification & Humidification"
Expand Down
22 changes: 18 additions & 4 deletions custom_components/philips_airpurifier_http/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from homeassistant.const import (
CONF_HOST,
CONF_NAME,
CONF_UNIQUE_ID,
)

from .const import *
Expand Down Expand Up @@ -121,8 +122,12 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
unique_id = None

wifi = await hass.async_add_executor_job(client.get_wifi)
if PHILIPS_MAC_ADDRESS in wifi:
unique_id = wifi[PHILIPS_MAC_ADDRESS]
else:
unique_id = config[CONF_UNIQUE_ID]

device = PhilipsAirPurifierFan(hass, client, name)
device = PhilipsAirPurifierFan(hass, client, name, unique_id)

if DATA_PHILIPS_FANS not in hass.data:
hass.data[DATA_PHILIPS_FANS] = []
Expand Down Expand Up @@ -173,11 +178,12 @@ async def async_service_handler(service):
class PhilipsAirPurifierFan(FanEntity):
"""philips_aurpurifier fan entity."""

def __init__(self, hass, client, name):
def __init__(self, hass, client, name, unique_id):
self.hass = hass
self._client = client
self._name = name

self._unique_id = unique_id
self._available = False
self._state = None
self._model = None
Expand Down Expand Up @@ -282,6 +288,12 @@ def available(self):
"""Return True when state is known."""
return self._available

@property
def unique_id(self):
"""Return an unique ID."""
return self._unique_id


@property
def name(self):
"""Return the name of the device if any."""
Expand Down Expand Up @@ -343,10 +355,12 @@ async def async_set_percentage(self, percentage: int) -> None:

async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set a preset mode on the fan."""

if preset_mode in MODE_MAP.values():
philips_mode = self._find_key(MODE_MAP, preset_mode)
await self._async_set_values({PHILIPS_MODE: philips_mode})
if philips_mode == "S":
await self._async_set_values({PHILIPS_MODE: "M", PHILIPS_SPEED: "s"})
else:
await self._async_set_values({PHILIPS_MODE: philips_mode})
else:
_LOGGER.warning('Unsupported preset mode "%s"', preset_mode)

Expand Down

0 comments on commit f0e2bd6

Please sign in to comment.