mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Add suggested area to hunterdouglas_powerview (#46774)
This commit is contained in:
parent
11277faa93
commit
4078a8782e
@ -77,9 +77,11 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
name_before_refresh,
|
name_before_refresh,
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
room_id = shade.raw_data.get(ROOM_ID_IN_SHADE)
|
||||||
|
room_name = room_data.get(room_id, {}).get(ROOM_NAME_UNICODE, "")
|
||||||
entities.append(
|
entities.append(
|
||||||
PowerViewShade(
|
PowerViewShade(
|
||||||
shade, name_before_refresh, room_data, coordinator, device_info
|
coordinator, device_info, room_name, shade, name_before_refresh
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
@ -98,17 +100,14 @@ def hass_position_to_hd(hass_positon):
|
|||||||
class PowerViewShade(ShadeEntity, CoverEntity):
|
class PowerViewShade(ShadeEntity, CoverEntity):
|
||||||
"""Representation of a powerview shade."""
|
"""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."""
|
"""Initialize the shade."""
|
||||||
room_id = shade.raw_data.get(ROOM_ID_IN_SHADE)
|
super().__init__(coordinator, device_info, room_name, shade, name)
|
||||||
super().__init__(coordinator, device_info, shade, name)
|
|
||||||
self._shade = shade
|
self._shade = shade
|
||||||
self._device_info = device_info
|
|
||||||
self._is_opening = False
|
self._is_opening = False
|
||||||
self._is_closing = False
|
self._is_closing = False
|
||||||
self._last_action_timestamp = 0
|
self._last_action_timestamp = 0
|
||||||
self._scheduled_transition_update = None
|
self._scheduled_transition_update = None
|
||||||
self._room_name = room_data.get(room_id, {}).get(ROOM_NAME_UNICODE, "")
|
|
||||||
self._current_cover_position = MIN_POSITION
|
self._current_cover_position = MIN_POSITION
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -23,9 +23,10 @@ from .const import (
|
|||||||
class HDEntity(CoordinatorEntity):
|
class HDEntity(CoordinatorEntity):
|
||||||
"""Base class for hunter douglas entities."""
|
"""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."""
|
"""Initialize the entity."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
self._room_name = room_name
|
||||||
self._unique_id = unique_id
|
self._unique_id = unique_id
|
||||||
self._device_info = device_info
|
self._device_info = device_info
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ class HDEntity(CoordinatorEntity):
|
|||||||
(dr.CONNECTION_NETWORK_MAC, self._device_info[DEVICE_MAC_ADDRESS])
|
(dr.CONNECTION_NETWORK_MAC, self._device_info[DEVICE_MAC_ADDRESS])
|
||||||
},
|
},
|
||||||
"name": self._device_info[DEVICE_NAME],
|
"name": self._device_info[DEVICE_NAME],
|
||||||
|
"suggested_area": self._room_name,
|
||||||
"model": self._device_info[DEVICE_MODEL],
|
"model": self._device_info[DEVICE_MODEL],
|
||||||
"sw_version": sw_version,
|
"sw_version": sw_version,
|
||||||
"manufacturer": MANUFACTURER,
|
"manufacturer": MANUFACTURER,
|
||||||
@ -54,9 +56,9 @@ class HDEntity(CoordinatorEntity):
|
|||||||
class ShadeEntity(HDEntity):
|
class ShadeEntity(HDEntity):
|
||||||
"""Base class for hunter douglas shade entities."""
|
"""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."""
|
"""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_name = shade_name
|
||||||
self._shade = shade
|
self._shade = shade
|
||||||
|
|
||||||
@ -67,6 +69,7 @@ class ShadeEntity(HDEntity):
|
|||||||
device_info = {
|
device_info = {
|
||||||
"identifiers": {(DOMAIN, self._shade.id)},
|
"identifiers": {(DOMAIN, self._shade.id)},
|
||||||
"name": self._shade_name,
|
"name": self._shade_name,
|
||||||
|
"suggested_area": self._room_name,
|
||||||
"manufacturer": MANUFACTURER,
|
"manufacturer": MANUFACTURER,
|
||||||
"via_device": (DOMAIN, self._device_info[DEVICE_SERIAL_NUMBER]),
|
"via_device": (DOMAIN, self._device_info[DEVICE_SERIAL_NUMBER]),
|
||||||
}
|
}
|
||||||
|
@ -49,23 +49,21 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
coordinator = pv_data[COORDINATOR]
|
coordinator = pv_data[COORDINATOR]
|
||||||
device_info = pv_data[DEVICE_INFO]
|
device_info = pv_data[DEVICE_INFO]
|
||||||
|
|
||||||
pvscenes = (
|
pvscenes = []
|
||||||
PowerViewScene(
|
for raw_scene in scene_data.values():
|
||||||
PvScene(raw_scene, pv_request), room_data, coordinator, device_info
|
scene = PvScene(raw_scene, pv_request)
|
||||||
)
|
room_name = room_data.get(scene.room_id, {}).get(ROOM_NAME_UNICODE, "")
|
||||||
for scene_id, raw_scene in scene_data.items()
|
pvscenes.append(PowerViewScene(coordinator, device_info, room_name, scene))
|
||||||
)
|
|
||||||
async_add_entities(pvscenes)
|
async_add_entities(pvscenes)
|
||||||
|
|
||||||
|
|
||||||
class PowerViewScene(HDEntity, Scene):
|
class PowerViewScene(HDEntity, Scene):
|
||||||
"""Representation of a Powerview 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."""
|
"""Initialize the scene."""
|
||||||
super().__init__(coordinator, device_info, scene.id)
|
super().__init__(coordinator, device_info, room_name, scene.id)
|
||||||
self._scene = scene
|
self._scene = scene
|
||||||
self._room_name = room_data.get(scene.room_id, {}).get(ROOM_NAME_UNICODE, "")
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -9,7 +9,10 @@ from .const import (
|
|||||||
DEVICE_INFO,
|
DEVICE_INFO,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
PV_API,
|
PV_API,
|
||||||
|
PV_ROOM_DATA,
|
||||||
PV_SHADE_DATA,
|
PV_SHADE_DATA,
|
||||||
|
ROOM_ID_IN_SHADE,
|
||||||
|
ROOM_NAME_UNICODE,
|
||||||
SHADE_BATTERY_LEVEL,
|
SHADE_BATTERY_LEVEL,
|
||||||
SHADE_BATTERY_LEVEL_MAX,
|
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."""
|
"""Set up the hunter douglas shades sensors."""
|
||||||
|
|
||||||
pv_data = hass.data[DOMAIN][entry.entry_id]
|
pv_data = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
room_data = pv_data[PV_ROOM_DATA]
|
||||||
shade_data = pv_data[PV_SHADE_DATA]
|
shade_data = pv_data[PV_SHADE_DATA]
|
||||||
pv_request = pv_data[PV_API]
|
pv_request = pv_data[PV_API]
|
||||||
coordinator = pv_data[COORDINATOR]
|
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:
|
if SHADE_BATTERY_LEVEL not in shade.raw_data:
|
||||||
continue
|
continue
|
||||||
name_before_refresh = shade.name
|
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(
|
entities.append(
|
||||||
PowerViewShadeBatterySensor(
|
PowerViewShadeBatterySensor(
|
||||||
coordinator, device_info, shade, name_before_refresh
|
coordinator, device_info, room_name, shade, name_before_refresh
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user