[go: nahoru, domu]

Skip to content

Commit

Permalink
Add Jci Hitachi Dehumidifier Light Integration (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
amigcamel committed Jan 11, 2024
1 parent a2eb291 commit 47ccbd0
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ A home assistant integration for controlling Jci Hitachi devices, using [LibJciH
- Air cleaning filter setting 空氣清淨濾網設定
- Power consumption 用電統計 (supports HA core v2021.9.0+)
- Monthly power consumption 月用電統計
- Display brightness 顯示器亮度
- ~~Sound control 聲音控制~~ (Only supported by LibJciHitachi)
- ~~Display brightness 顯示器亮度~~ (Only supported by LibJciHitachi)
- ~~Side vent 側吹~~ (Only supported by LibJciHitachi)
- Hitachi Heat Exchanger 日立全熱交換機
- Power 電源
Expand Down
2 changes: 1 addition & 1 deletion custom_components/jcihitachi_tw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
UPDATED_DATA)

_LOGGER = logging.getLogger(__name__)
PLATFORMS = ["binary_sensor", "climate", "fan", "humidifier", "number", "sensor", "switch"]
PLATFORMS = ["binary_sensor", "climate", "fan", "humidifier", "number", "sensor", "switch", "light"]
DATA_UPDATE_INTERVAL = timedelta(seconds=30)
BASE_TIMEOUT = 5

Expand Down
97 changes: 97 additions & 0 deletions custom_components/jcihitachi_tw/light.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import logging
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
SUPPORT_BRIGHTNESS,
LightEntity,
)

from . import API, COORDINATOR, DOMAIN, UPDATED_DATA, JciHitachiEntity

_LOGGER = logging.getLogger(__name__)


async def _async_setup(hass, async_add):
api = hass.data[DOMAIN][API]
coordinator = hass.data[DOMAIN][COORDINATOR]

for thing in api.things.values():
if thing.type == "DH":
async_add(
[JciHitachiDehumidifierLightEntity(thing, coordinator)],
update_before_add=True,
)


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
await _async_setup(hass, async_add_entities)


async def async_setup_entry(hass, config_entry, async_add_devices):
await _async_setup(hass, async_add_devices)


class JciHitachiDehumidifierLightEntity(JciHitachiEntity, LightEntity):
brightness_mapping = {
"bright": 255,
"dark": 170,
"off": 85,
"all_off": 0,
}

def __init__(self, thing, coordinator):
super().__init__(thing, coordinator)

@property
def unique_id(self):
return f"{self._thing.gateway_mac_address}_dehumidifier_light"

@property
def name(self):
return f"{self._thing.name} panel LED"

@property
def supported_features(self):
return SUPPORT_BRIGHTNESS

@property
def is_on(self):
"""Return true if the entity is on"""
status = self.hass.data[DOMAIN][UPDATED_DATA][self._thing.name]
if status:
if status.display_brightness == "all_off":
return False
else:
return True

_LOGGER.error("Missing is_on.")
return None

@property
def brightness(self):
status = self.hass.data[DOMAIN][UPDATED_DATA][self._thing.name]
if status:
return self.brightness_mapping.get(status.display_brightness, 0)

_LOGGER.error("Missing brightness.")
return 0

def turn_on(self, **kwargs):
_LOGGER.debug(f"Turn {self.name} on")
brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
if brightness > 170:
brightness_value = "bright"
elif brightness <= 170 and brightness > 85:
brightness_value = "dark"
elif brightness <= 85 and brightness > 3:
brightness_value = "off"
else:
brightness_value = "all_off"
self.put_queue(
status_name="display_brightness", status_str_value=brightness_value
)
self.update()

def turn_off(self, **kwargs):
_LOGGER.debug(f"Turn {self.name} off")
self.put_queue(status_name="display_brightness", status_str_value="all_off")
self.update()

0 comments on commit 47ccbd0

Please sign in to comment.