Skip to content

Commit

Permalink
Merge pull request #9 from mikelawrence/haiku-light
Browse files Browse the repository at this point in the history
Haiku light
  • Loading branch information
mikelawrence authored May 26, 2020
2 parents 76aba1b + 556adcc commit 6725d0e
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog for Home Assistant integration for SenseME fans

## 2.1.0 - Support standalone Haiku Light

* Haiku Light supports brightness, color temp and occupancy sensor. Kudos to [PenitentTangent2401](https://github.com/mikelawrence/senseme-hacs/issues/7) for his assistance in testing and debugging these changes.

## 2.0.10 - Fix problems caused by 2.0.9

* Removed changes in 2.0.9 that caused problems for some users. No changes to integration functionality.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ If you have HACS installed on Home Assistant then just search integrations for *

Copy the custom_components folder of this repository to your config folder and restart Home Assistant.

## Configuration using Home Assistant frontend
## Configuration using Home Assistant UI

* Go to **Configuration -> Integrations**.
* Click on the **+** in the bottom right corner to add a new integration.
Expand Down
21 changes: 10 additions & 11 deletions custom_components/senseme/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,27 @@


async def async_setup_entry(hass, entry, async_add_entities):
"""Set up SenseME sensors."""
"""Set up SenseME occupancy sensors."""
if hass.data.get(DOMAIN) is None:
hass.data[DOMAIN] = {}
if hass.data[DOMAIN].get("sensor_devices") is None:
hass.data[DOMAIN]["sensor_devices"] = []

async def async_discovered_fans(fans: list):
"""Async handle a (re)discovered SenseME fans."""
async def async_discovered_devices(devices: list):
"""Async handle a (re)discovered SenseME devices."""
new_sensors = []
for fan in fans:
if fan not in hass.data[DOMAIN]["sensor_devices"]:
# L Series fans do not have an occupancy sensor
if fan.model != "Haiku L Fan":
fan.refreshMinutes = UPDATE_RATE
hass.data[DOMAIN]["sensor_devices"].append(fan)
sensor = HASensemeOccupancySensor(fan)
for device in devices:
if device not in hass.data[DOMAIN]["sensor_devices"]:
if device.has_sensor:
device.refreshMinutes = UPDATE_RATE
hass.data[DOMAIN]["sensor_devices"].append(device)
sensor = HASensemeOccupancySensor(device)
new_sensors.append(sensor)
_LOGGER.debug("Added new sensor: %s", sensor.name)
if len(new_sensors) > 0:
hass.add_job(async_add_entities, new_sensors)

hass.data[DOMAIN]["discovery"].add_callback(async_discovered_fans)
hass.data[DOMAIN]["discovery"].add_callback(async_discovered_devices)


class HASensemeOccupancySensor(BinarySensorEntity):
Expand Down
24 changes: 13 additions & 11 deletions custom_components/senseme/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,25 @@ async def async_setup_entry(hass, entry, async_add_entities):
if hass.data[DOMAIN].get("fan_devices") is None:
hass.data[DOMAIN]["fan_devices"] = []

async def async_discovered_fans(fans: list):
"""Async handle (re)discovered SenseME fans."""
async def async_discovered_devices(devices: list):
"""Async handle (re)discovered SenseME devices."""
new_fans = []
for fan in fans:
if fan not in hass.data[DOMAIN]["fan_devices"]:
fan.refreshMinutes = UPDATE_RATE
hass.data[DOMAIN]["fan_devices"].append(fan)
new_fans.append(HASensemeFan(hass, entry, fan))
_LOGGER.debug("Added new fan: %s", fan.name)
if "Haiku" not in fan.model and "Fan" not in fan.model:
for device in devices:
if device not in hass.data[DOMAIN]["fan_devices"]:
if device.is_fan:
device.refreshMinutes = UPDATE_RATE
hass.data[DOMAIN]["fan_devices"].append(device)
new_fans.append(HASensemeFan(hass, entry, device))
_LOGGER.debug("Added new fan: %s", device.name)
if device.is_unknown_model:
_LOGGER.warning(
"Discovered unknown SenseME device model='%s'", fan.model
"Discovered unknown SenseME device model='%s' assuming it is a fan",
device.model,
)
if len(new_fans) > 0:
hass.add_job(async_add_entities, new_fans)

hass.data[DOMAIN]["discovery"].add_callback(async_discovered_fans)
hass.data[DOMAIN]["discovery"].add_callback(async_discovered_devices)


class HASensemeFan(FanEntity):
Expand Down
54 changes: 44 additions & 10 deletions custom_components/senseme/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR_TEMP,
LightEntity,
)

Expand All @@ -19,21 +21,21 @@ async def async_setup_entry(hass, entry, async_add_entities):
if not hass.data[DOMAIN].get("light_devices"):
hass.data[DOMAIN]["light_devices"] = []

async def async_discovered_fans(fans: list):
"""Async handle a (re)discovered SenseME fans."""
async def async_discovered_devices(devices: list):
"""Async handle a (re)discovered SenseME devices."""
new_lights = []
for fan in fans:
if fan not in hass.data[DOMAIN]["light_devices"]:
if fan.has_light:
fan.refreshMinutes = UPDATE_RATE
hass.data[DOMAIN]["light_devices"].append(fan)
light = HASensemeLight(fan)
for device in devices:
if device not in hass.data[DOMAIN]["light_devices"]:
if device.has_light:
device.refreshMinutes = UPDATE_RATE
hass.data[DOMAIN]["light_devices"].append(device)
light = HASensemeLight(device)
new_lights.append(light)
_LOGGER.debug("Added new light: %s", light.name)
if len(new_lights) > 0:
hass.add_job(async_add_entities, new_lights)

hass.data[DOMAIN]["discovery"].add_callback(async_discovered_fans)
hass.data[DOMAIN]["discovery"].add_callback(async_discovered_devices)


class HASensemeLight(LightEntity):
Expand All @@ -42,8 +44,13 @@ class HASensemeLight(LightEntity):
def __init__(self, device):
"""Initialize the entity."""
self.device = device
self._name = device.name + " Light"
if device.is_light:
self._name = device.name
else:
self._name = device.name + " Light"
self._supported_features = SUPPORT_BRIGHTNESS
if device.is_light:
self._supported_features |= SUPPORT_COLOR_TEMP

async def async_added_to_hass(self):
"""Add data updated listener after this object has been initialized."""
Expand Down Expand Up @@ -105,6 +112,30 @@ def brightness(self) -> int:
light_brightness = 255
return int(light_brightness)

@property
def color_temp(self):
"""Return the color temp value in mireds."""
if not self.device.is_light:
return None
color_temp = int(round(1000000.0 / float(self.device.light_color_temp)))
return color_temp

@property
def min_mireds(self):
"""Return the coldest color temp that this light supports."""
if not self.device.is_light:
return None
color_temp = int(round(1000000.0 / float(self.device.light_color_temp_max)))
return color_temp

@property
def max_mireds(self):
"""Return the warmest color temp that this light supports."""
if not self.device.is_light:
return None
color_temp = int(round(1000000.0 / float(self.device.light_color_temp_min)))
return color_temp

@property
def supported_features(self) -> int:
"""Flag supported features."""
Expand All @@ -113,6 +144,9 @@ def supported_features(self) -> int:
def turn_on(self, **kwargs) -> None:
"""Turn on the light."""
brightness = kwargs.get(ATTR_BRIGHTNESS)
color_temp = kwargs.get(ATTR_COLOR_TEMP)
if color_temp is not None:
self.device.light_color_temp = int(round(1000000.0 / float(color_temp)))
if brightness is None:
# no brightness, just turn the light on
self.device.light_on = True
Expand Down
2 changes: 1 addition & 1 deletion custom_components/senseme/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.github.com/mikelawrence/senseme-hacs",
"requirements": [
"aiosenseme>=0.3.3,<0.4.0"
"aiosenseme>=0.4.1,<0.5.0"
],
"ssdp": [],
"zeroconf": [],
Expand Down
2 changes: 1 addition & 1 deletion custom_components/senseme/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version for senseme-hacs."""

__version__ = "2.0.10"
__version__ = "2.1.0"
7 changes: 3 additions & 4 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ The Haiku with SenseME fan is a WiFi connected fan and optional light from Big A
* Confirmed support of Haiku, Haiku H, and Haiku L fans.
* Probably supports Haiku C fans. If you have a Haiku C fan you should be seeing a warning about an unknown model in the Home Assistant log. Please open an issue [here](https://github.com/mikelawrence/senseme-hacs/issues) to let me know the model name.
* Configuration via Home Assistant frontend.
* Fan supports speed, direction and whoosh as oscillate.
* Light supported if installed.
* Occupancy sensor supported.
* Control of any one fan in a room (Haiku App configured) affects all fans in that room.
* Fan supports speed, direction, whoosh as oscillate, light if installed and occupancy sensor if available.
* Haiku Light supports brightness, color temp and occupancy sensor.
* Control of any one device in a room (Haiku App configured) affects all devices in that room.

### Usage

Expand Down

0 comments on commit 6725d0e

Please sign in to comment.