Skip to content

Commit

Permalink
Merge pull request #43 from bjorncs/bjorncs/suggested-area
Browse files Browse the repository at this point in the history
Pre-populate area name based on Dirigera room definition
  • Loading branch information
sanjoyg authored Apr 22, 2024
2 parents 97424cd + 055ad83 commit 34d44cc
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions custom_components/dirigera_platform/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def device_info(self) -> DeviceInfo:
manufacturer=self._json_data.attributes.manufacturer,
model=self._json_data.attributes.model,
sw_version=self._json_data.attributes.firmware_version,
suggested_area=self._json_data.room.name if self._json_data.room is not None else None,
)

@property
Expand Down Expand Up @@ -142,6 +143,7 @@ def device_info(self) -> DeviceInfo:
manufacturer=self._json_data.attributes.manufacturer,
model=self._json_data.attributes.model,
sw_version=self._json_data.attributes.firmware_version,
suggested_area=self._json_data.room.name if self._json_data.room is not None else None,
)

@property
Expand Down Expand Up @@ -220,6 +222,7 @@ def device_info(self) -> DeviceInfo:
manufacturer=self._json_data.attributes.manufacturer,
model=self._json_data.attributes.model,
sw_version=self._json_data.attributes.firmware_version,
suggested_area=self._json_data.room.name if self._json_data.room is not None else None,
)

@property
Expand Down
1 change: 1 addition & 0 deletions custom_components/dirigera_platform/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def device_info(self) -> DeviceInfo:
manufacturer=self._json_data.attributes.manufacturer,
model=self._json_data.attributes.model,
sw_version=self._json_data.attributes.firmware_version,
suggested_area=self._json_data.room.name if self._json_data.room is not None else None,
)

@property
Expand Down
1 change: 1 addition & 0 deletions custom_components/dirigera_platform/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def device_info(self) -> DeviceInfo:
manufacturer=self._json_data.attributes.manufacturer,
model=self._json_data.attributes.model,
sw_version=self._json_data.attributes.firmware_version,
suggested_area=self._json_data.room.name if self._json_data.room is not None else None,
)

@property
Expand Down
19 changes: 15 additions & 4 deletions custom_components/dirigera_platform/light.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import logging
from typing import Optional
import dirigera

from dirigera import Hub
from dirigera.devices.device import Room
from homeassistant import config_entries, core
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
Expand Down Expand Up @@ -59,11 +61,13 @@ async def async_setup_entry(
for one_set in light._json_data.device_set:
id = one_set['id']
name = one_set['name']
# Use the room of the first light encountered in the set as the 'suggested area' for HA
suggested_room = light._json_data.room

target_device_set = None
if id not in device_sets:
logger.debug(f"Found new device set {name}")
device_sets[id] = device_set_model(id, name)
device_sets[id] = device_set_model(id, name, suggested_room)

target_device_set = device_sets[id]
target_device_set.add_light(light)
Expand All @@ -81,19 +85,24 @@ async def async_setup_entry(
logger.debug("LIGHT Complete async_setup_entry")

class device_set_model:
def __init__(self, id, name):
def __init__(self, id, name, suggested_room: Optional[Room]):
logger.debug(f"device_set ctor {id} : {name}")
self._lights = []
self._name = name
self._id = id
self._id = id
self._suggested_room = suggested_room

@property
def id(self):
return self._id

@property
def name(self):
return self._name
return self._name

@property
def suggested_room(self) -> Optional[Room]:
return self._suggested_room

def get_lights(self) -> list:
return self._lights
Expand Down Expand Up @@ -172,6 +181,7 @@ def device_info(self) -> DeviceInfo:
manufacturer=self._json_data.attributes.manufacturer,
model=self._json_data.attributes.model,
sw_version=self._json_data.attributes.firmware_version,
suggested_area=self._json_data.room.name if self._json_data.room is not None else None,
)

@property
Expand Down Expand Up @@ -326,6 +336,7 @@ def device_info(self) -> DeviceInfo:
manufacturer="IKEA",
model="Device Set",
sw_version="1.0",
suggested_area=self._device_set.suggested_room.name if self._device_set.suggested_room is not None else None,
)

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def device_info(self) -> DeviceInfo:
manufacturer="MOCK",
model="Mock 1.0",
sw_version="Mock SW 1.0",
suggested_area="Kitchen",
)

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def device_info(self) -> DeviceInfo:
manufacturer=self._manufacturer,
model=self._model,
sw_version=self._sw_version,
suggested_area="Bedroom",
)

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def device_info(self) -> DeviceInfo:
manufacturer=self._manufacturer,
model=self._model,
sw_version=self._sw_version,
suggested_area="Living room",
)

@property
Expand Down
2 changes: 2 additions & 0 deletions custom_components/dirigera_platform/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def device_info(self) -> DeviceInfo:
manufacturer=self._json_data.attributes.manufacturer,
model=self._json_data.attributes.model,
sw_version=self._json_data.attributes.firmware_version,
suggested_area=self._json_data.room.name if self._json_data.room is not None else None,
)

@property
Expand Down Expand Up @@ -308,6 +309,7 @@ def device_info(self) -> DeviceInfo:
manufacturer=self._json_data.attributes.manufacturer,
model=self._json_data.attributes.model,
sw_version=self._json_data.attributes.firmware_version,
suggested_area=self._json_data.room.name if self._json_data.room is not None else None,
)

@property
Expand Down
1 change: 1 addition & 0 deletions custom_components/dirigera_platform/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def device_info(self) -> DeviceInfo:
manufacturer=self._json_data.attributes.manufacturer,
model=self._json_data.attributes.model,
sw_version=self._json_data.attributes.firmware_version,
suggested_area=self._json_data.room.name if self._json_data.room is not None else None,
)

@property
Expand Down

0 comments on commit 34d44cc

Please sign in to comment.