Add suggested area to hunterdouglas_powerview (#46774)

This commit is contained in:
J. Nick Koston 2021-02-19 20:17:00 -10:00 committed by GitHub
parent 11277faa93
commit 4078a8782e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 19 deletions

View File

@ -77,9 +77,11 @@ async def async_setup_entry(hass, entry, async_add_entities):
name_before_refresh,
)
continue
room_id = shade.raw_data.get(ROOM_ID_IN_SHADE)
room_name = room_data.get(room_id, {}).get(ROOM_NAME_UNICODE, "")
entities.append(
PowerViewShade(
shade, name_before_refresh, room_data, coordinator, device_info
coordinator, device_info, room_name, shade, name_before_refresh
)
)
async_add_entities(entities)
@ -98,17 +100,14 @@ def hass_position_to_hd(hass_positon):
class PowerViewShade(ShadeEntity, CoverEntity):
"""Representation of a powerview shade."""
def __init__(self, shade, name, room_data, coordinator, device_info):
def __init__(self, coordinator, device_info, room_name, shade, name):
"""Initialize the shade."""
room_id = shade.raw_data.get(ROOM_ID_IN_SHADE)
super().__init__(coordinator, device_info, shade, name)
super().__init__(coordinator, device_info, room_name, shade, name)
self._shade = shade
self._device_info = device_info
self._is_opening = False
self._is_closing = False
self._last_action_timestamp = 0
self._scheduled_transition_update = None
self._room_name = room_data.get(room_id, {}).get(ROOM_NAME_UNICODE, "")
self._current_cover_position = MIN_POSITION
@property

View File

@ -23,9 +23,10 @@ from .const import (
class HDEntity(CoordinatorEntity):
"""Base class for hunter douglas entities."""
def __init__(self, coordinator, device_info, unique_id):
def __init__(self, coordinator, device_info, room_name, unique_id):
"""Initialize the entity."""
super().__init__(coordinator)
self._room_name = room_name
self._unique_id = unique_id
self._device_info = device_info
@ -45,6 +46,7 @@ class HDEntity(CoordinatorEntity):
(dr.CONNECTION_NETWORK_MAC, self._device_info[DEVICE_MAC_ADDRESS])
},
"name": self._device_info[DEVICE_NAME],
"suggested_area": self._room_name,
"model": self._device_info[DEVICE_MODEL],
"sw_version": sw_version,
"manufacturer": MANUFACTURER,
@ -54,9 +56,9 @@ class HDEntity(CoordinatorEntity):
class ShadeEntity(HDEntity):
"""Base class for hunter douglas shade entities."""
def __init__(self, coordinator, device_info, shade, shade_name):
def __init__(self, coordinator, device_info, room_name, shade, shade_name):
"""Initialize the shade."""
super().__init__(coordinator, device_info, shade.id)
super().__init__(coordinator, device_info, room_name, shade.id)
self._shade_name = shade_name
self._shade = shade
@ -67,6 +69,7 @@ class ShadeEntity(HDEntity):
device_info = {
"identifiers": {(DOMAIN, self._shade.id)},
"name": self._shade_name,
"suggested_area": self._room_name,
"manufacturer": MANUFACTURER,
"via_device": (DOMAIN, self._device_info[DEVICE_SERIAL_NUMBER]),
}

View File

@ -49,23 +49,21 @@ async def async_setup_entry(hass, entry, async_add_entities):
coordinator = pv_data[COORDINATOR]
device_info = pv_data[DEVICE_INFO]
pvscenes = (
PowerViewScene(
PvScene(raw_scene, pv_request), room_data, coordinator, device_info
)
for scene_id, raw_scene in scene_data.items()
)
pvscenes = []
for raw_scene in scene_data.values():
scene = PvScene(raw_scene, pv_request)
room_name = room_data.get(scene.room_id, {}).get(ROOM_NAME_UNICODE, "")
pvscenes.append(PowerViewScene(coordinator, device_info, room_name, scene))
async_add_entities(pvscenes)
class PowerViewScene(HDEntity, Scene):
"""Representation of a Powerview scene."""
def __init__(self, scene, room_data, coordinator, device_info):
def __init__(self, coordinator, device_info, room_name, scene):
"""Initialize the scene."""
super().__init__(coordinator, device_info, scene.id)
super().__init__(coordinator, device_info, room_name, scene.id)
self._scene = scene
self._room_name = room_data.get(scene.room_id, {}).get(ROOM_NAME_UNICODE, "")
@property
def name(self):

View File

@ -9,7 +9,10 @@ from .const import (
DEVICE_INFO,
DOMAIN,
PV_API,
PV_ROOM_DATA,
PV_SHADE_DATA,
ROOM_ID_IN_SHADE,
ROOM_NAME_UNICODE,
SHADE_BATTERY_LEVEL,
SHADE_BATTERY_LEVEL_MAX,
)
@ -20,6 +23,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
"""Set up the hunter douglas shades sensors."""
pv_data = hass.data[DOMAIN][entry.entry_id]
room_data = pv_data[PV_ROOM_DATA]
shade_data = pv_data[PV_SHADE_DATA]
pv_request = pv_data[PV_API]
coordinator = pv_data[COORDINATOR]
@ -31,9 +35,11 @@ async def async_setup_entry(hass, entry, async_add_entities):
if SHADE_BATTERY_LEVEL not in shade.raw_data:
continue
name_before_refresh = shade.name
room_id = shade.raw_data.get(ROOM_ID_IN_SHADE)
room_name = room_data.get(room_id, {}).get(ROOM_NAME_UNICODE, "")
entities.append(
PowerViewShadeBatterySensor(
coordinator, device_info, shade, name_before_refresh
coordinator, device_info, room_name, shade, name_before_refresh
)
)
async_add_entities(entities)