mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Reorg channel handling for Homematic IP Cloud (#41118)
This commit is contained in:
parent
c00915a6a7
commit
5721225dde
@ -99,7 +99,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
|||||||
# Add the HAP name from configuration if set.
|
# Add the HAP name from configuration if set.
|
||||||
hapname = home.label if not home.name else f"{home.name} {home.label}"
|
hapname = home.label if not home.name else f"{home.name} {home.label}"
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
config_entry_id=home.id,
|
config_entry_id=entry.entry_id,
|
||||||
identifiers={(DOMAIN, home.id)},
|
identifiers={(DOMAIN, home.id)},
|
||||||
manufacturer="eQ-3",
|
manufacturer="eQ-3",
|
||||||
name=hapname,
|
name=hapname,
|
||||||
|
@ -128,9 +128,9 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
for group in hap.home.groups:
|
for group in hap.home.groups:
|
||||||
if isinstance(group, AsyncSecurityGroup):
|
if isinstance(group, AsyncSecurityGroup):
|
||||||
entities.append(HomematicipSecuritySensorGroup(hap, group))
|
entities.append(HomematicipSecuritySensorGroup(hap, device=group))
|
||||||
elif isinstance(group, AsyncSecurityZoneGroup):
|
elif isinstance(group, AsyncSecurityZoneGroup):
|
||||||
entities.append(HomematicipSecurityZoneSensorGroup(hap, group))
|
entities.append(HomematicipSecurityZoneSensorGroup(hap, device=group))
|
||||||
|
|
||||||
if entities:
|
if entities:
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
@ -361,7 +361,7 @@ class HomematicipSunshineSensor(HomematicipGenericEntity, BinarySensorEntity):
|
|||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device) -> None:
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
||||||
"""Initialize sunshine sensor."""
|
"""Initialize sunshine sensor."""
|
||||||
super().__init__(hap, device, "Sunshine")
|
super().__init__(hap, device, post="Sunshine")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self) -> str:
|
def device_class(self) -> str:
|
||||||
@ -390,7 +390,7 @@ class HomematicipBatterySensor(HomematicipGenericEntity, BinarySensorEntity):
|
|||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device) -> None:
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
||||||
"""Initialize battery sensor."""
|
"""Initialize battery sensor."""
|
||||||
super().__init__(hap, device, "Battery")
|
super().__init__(hap, device, post="Battery")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self) -> str:
|
def device_class(self) -> str:
|
||||||
@ -429,7 +429,7 @@ class HomematicipSecurityZoneSensorGroup(HomematicipGenericEntity, BinarySensorE
|
|||||||
def __init__(self, hap: HomematicipHAP, device, post: str = "SecurityZone") -> None:
|
def __init__(self, hap: HomematicipHAP, device, post: str = "SecurityZone") -> None:
|
||||||
"""Initialize security zone group."""
|
"""Initialize security zone group."""
|
||||||
device.modelType = f"HmIP-{post}"
|
device.modelType = f"HmIP-{post}"
|
||||||
super().__init__(hap, device, post)
|
super().__init__(hap, device, post=post)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self) -> str:
|
def device_class(self) -> str:
|
||||||
@ -485,7 +485,7 @@ class HomematicipSecuritySensorGroup(
|
|||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device) -> None:
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
||||||
"""Initialize security group."""
|
"""Initialize security group."""
|
||||||
super().__init__(hap, device, "Sensors")
|
super().__init__(hap, device, post="Sensors")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self) -> Dict[str, Any]:
|
def device_state_attributes(self) -> Dict[str, Any]:
|
||||||
|
@ -70,12 +70,19 @@ GROUP_ATTRIBUTES = {
|
|||||||
class HomematicipGenericEntity(Entity):
|
class HomematicipGenericEntity(Entity):
|
||||||
"""Representation of the HomematicIP generic entity."""
|
"""Representation of the HomematicIP generic entity."""
|
||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device, post: Optional[str] = None) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
hap: HomematicipHAP,
|
||||||
|
device,
|
||||||
|
post: Optional[str] = None,
|
||||||
|
channel: Optional[int] = None,
|
||||||
|
) -> None:
|
||||||
"""Initialize the generic entity."""
|
"""Initialize the generic entity."""
|
||||||
self._hap = hap
|
self._hap = hap
|
||||||
self._home = hap.home
|
self._home = hap.home
|
||||||
self._device = device
|
self._device = device
|
||||||
self.post = post
|
self._post = post
|
||||||
|
self._channel = channel
|
||||||
# Marker showing that the HmIP device hase been removed.
|
# Marker showing that the HmIP device hase been removed.
|
||||||
self.hmip_device_removed = False
|
self.hmip_device_removed = False
|
||||||
_LOGGER.info("Setting up %s (%s)", self.name, self._device.modelType)
|
_LOGGER.info("Setting up %s (%s)", self.name, self._device.modelType)
|
||||||
@ -94,6 +101,7 @@ class HomematicipGenericEntity(Entity):
|
|||||||
"manufacturer": self._device.oem,
|
"manufacturer": self._device.oem,
|
||||||
"model": self._device.modelType,
|
"model": self._device.modelType,
|
||||||
"sw_version": self._device.firmwareVersion,
|
"sw_version": self._device.firmwareVersion,
|
||||||
|
# Link to the homematic ip access point.
|
||||||
"via_device": (HMIPC_DOMAIN, self._device.homeId),
|
"via_device": (HMIPC_DOMAIN, self._device.homeId),
|
||||||
}
|
}
|
||||||
return None
|
return None
|
||||||
@ -167,18 +175,28 @@ class HomematicipGenericEntity(Entity):
|
|||||||
@property
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Return the name of the generic entity."""
|
"""Return the name of the generic entity."""
|
||||||
name = self._device.label
|
|
||||||
if name and self._home.name:
|
|
||||||
name = f"{self._home.name} {name}"
|
|
||||||
if name and self.post:
|
|
||||||
name = f"{name} {self.post}"
|
|
||||||
return name
|
|
||||||
|
|
||||||
def _get_label_by_channel(self, channel: int) -> str:
|
name = None
|
||||||
"""Return the name of the channel."""
|
# Try to get a label from a channel.
|
||||||
name = self._device.functionalChannels[channel].label
|
if hasattr(self._device, "functionalChannels"):
|
||||||
|
if self._channel:
|
||||||
|
name = self._device.functionalChannels[self._channel].label
|
||||||
|
else:
|
||||||
|
if len(self._device.functionalChannels) > 1:
|
||||||
|
name = self._device.functionalChannels[1].label
|
||||||
|
|
||||||
|
# Use device label, if name is not defined by channel label.
|
||||||
|
if not name:
|
||||||
|
name = self._device.label
|
||||||
|
if self._post:
|
||||||
|
name = f"{name} {self._post}"
|
||||||
|
elif self._channel:
|
||||||
|
name = f"{name} Channel{self._channel}"
|
||||||
|
|
||||||
|
# Add a prefix to the name if the homematic ip home has a name.
|
||||||
if name and self._home.name:
|
if name and self._home.name:
|
||||||
name = f"{self._home.name} {name}"
|
name = f"{self._home.name} {name}"
|
||||||
|
|
||||||
return name
|
return name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -194,7 +212,13 @@ class HomematicipGenericEntity(Entity):
|
|||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
"""Return a unique ID."""
|
"""Return a unique ID."""
|
||||||
return f"{self.__class__.__name__}_{self._device.id}"
|
unique_id = f"{self.__class__.__name__}_{self._device.id}"
|
||||||
|
if self._channel:
|
||||||
|
unique_id = (
|
||||||
|
f"{self.__class__.__name__}_Channel{self._channel}_{self._device.id}"
|
||||||
|
)
|
||||||
|
|
||||||
|
return unique_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self) -> Optional[str]:
|
def icon(self) -> Optional[str]:
|
||||||
|
@ -71,14 +71,6 @@ class HomematicipLight(HomematicipGenericEntity, LightEntity):
|
|||||||
"""Initialize the light entity."""
|
"""Initialize the light entity."""
|
||||||
super().__init__(hap, device)
|
super().__init__(hap, device)
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of the multi switch channel."""
|
|
||||||
label = self._get_label_by_channel(1)
|
|
||||||
if label:
|
|
||||||
return label
|
|
||||||
return super().name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return true if light is on."""
|
"""Return true if light is on."""
|
||||||
@ -149,11 +141,10 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
|
|||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device, channel: int) -> None:
|
def __init__(self, hap: HomematicipHAP, device, channel: int) -> None:
|
||||||
"""Initialize the notification light entity."""
|
"""Initialize the notification light entity."""
|
||||||
self.channel = channel
|
if channel == 2:
|
||||||
if self.channel == 2:
|
super().__init__(hap, device, post="Top", channel=channel)
|
||||||
super().__init__(hap, device, "Top")
|
|
||||||
else:
|
else:
|
||||||
super().__init__(hap, device, "Bottom")
|
super().__init__(hap, device, post="Bottom", channel=channel)
|
||||||
|
|
||||||
self._color_switcher = {
|
self._color_switcher = {
|
||||||
RGBColorState.WHITE: [0.0, 0.0],
|
RGBColorState.WHITE: [0.0, 0.0],
|
||||||
@ -167,7 +158,7 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def _func_channel(self) -> NotificationLightChannel:
|
def _func_channel(self) -> NotificationLightChannel:
|
||||||
return self._device.functionalChannels[self.channel]
|
return self._device.functionalChannels[self._channel]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
@ -198,14 +189,6 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
|
|||||||
|
|
||||||
return state_attr
|
return state_attr
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of the notification light sensor."""
|
|
||||||
label = self._get_label_by_channel(self.channel)
|
|
||||||
if label:
|
|
||||||
return label
|
|
||||||
return f"{super().name} Notification"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
@ -214,7 +197,7 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
|
|||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
"""Return a unique ID."""
|
"""Return a unique ID."""
|
||||||
return f"{self.__class__.__name__}_{self.post}_{self._device.id}"
|
return f"{self.__class__.__name__}_{self._post}_{self._device.id}"
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs) -> None:
|
async def async_turn_on(self, **kwargs) -> None:
|
||||||
"""Turn the light on."""
|
"""Turn the light on."""
|
||||||
@ -237,7 +220,7 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
|
|||||||
transition = kwargs.get(ATTR_TRANSITION, 0.5)
|
transition = kwargs.get(ATTR_TRANSITION, 0.5)
|
||||||
|
|
||||||
await self._device.set_rgb_dim_level_with_time(
|
await self._device.set_rgb_dim_level_with_time(
|
||||||
channelIndex=self.channel,
|
channelIndex=self._channel,
|
||||||
rgb=simple_rgb_color,
|
rgb=simple_rgb_color,
|
||||||
dimLevel=dim_level,
|
dimLevel=dim_level,
|
||||||
onTime=0,
|
onTime=0,
|
||||||
@ -250,7 +233,7 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
|
|||||||
transition = kwargs.get(ATTR_TRANSITION, 0.5)
|
transition = kwargs.get(ATTR_TRANSITION, 0.5)
|
||||||
|
|
||||||
await self._device.set_rgb_dim_level_with_time(
|
await self._device.set_rgb_dim_level_with_time(
|
||||||
channelIndex=self.channel,
|
channelIndex=self._channel,
|
||||||
rgb=simple_rgb_color,
|
rgb=simple_rgb_color,
|
||||||
dimLevel=0.0,
|
dimLevel=0.0,
|
||||||
onTime=0,
|
onTime=0,
|
||||||
|
@ -127,7 +127,7 @@ class HomematicipAccesspointStatus(HomematicipGenericEntity):
|
|||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP) -> None:
|
def __init__(self, hap: HomematicipHAP) -> None:
|
||||||
"""Initialize access point status entity."""
|
"""Initialize access point status entity."""
|
||||||
super().__init__(hap, hap.home, "Duty Cycle")
|
super().__init__(hap, device=hap.home, post="Duty Cycle")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> Dict[str, Any]:
|
def device_info(self) -> Dict[str, Any]:
|
||||||
@ -176,7 +176,7 @@ class HomematicipHeatingThermostat(HomematicipGenericEntity):
|
|||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device) -> None:
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
||||||
"""Initialize heating thermostat device."""
|
"""Initialize heating thermostat device."""
|
||||||
super().__init__(hap, device, "Heating")
|
super().__init__(hap, device, post="Heating")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self) -> str:
|
def icon(self) -> str:
|
||||||
@ -205,7 +205,7 @@ class HomematicipHumiditySensor(HomematicipGenericEntity):
|
|||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device) -> None:
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
||||||
"""Initialize the thermometer device."""
|
"""Initialize the thermometer device."""
|
||||||
super().__init__(hap, device, "Humidity")
|
super().__init__(hap, device, post="Humidity")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self) -> str:
|
def device_class(self) -> str:
|
||||||
@ -228,7 +228,7 @@ class HomematicipTemperatureSensor(HomematicipGenericEntity):
|
|||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device) -> None:
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
||||||
"""Initialize the thermometer device."""
|
"""Initialize the thermometer device."""
|
||||||
super().__init__(hap, device, "Temperature")
|
super().__init__(hap, device, post="Temperature")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self) -> str:
|
def device_class(self) -> str:
|
||||||
@ -265,7 +265,7 @@ class HomematicipIlluminanceSensor(HomematicipGenericEntity):
|
|||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device) -> None:
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
||||||
"""Initialize the device."""
|
"""Initialize the device."""
|
||||||
super().__init__(hap, device, "Illuminance")
|
super().__init__(hap, device, post="Illuminance")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self) -> str:
|
def device_class(self) -> str:
|
||||||
@ -303,7 +303,7 @@ class HomematicipPowerSensor(HomematicipGenericEntity):
|
|||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device) -> None:
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
||||||
"""Initialize the device."""
|
"""Initialize the device."""
|
||||||
super().__init__(hap, device, "Power")
|
super().__init__(hap, device, post="Power")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self) -> str:
|
def device_class(self) -> str:
|
||||||
@ -326,7 +326,7 @@ class HomematicipWindspeedSensor(HomematicipGenericEntity):
|
|||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device) -> None:
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
||||||
"""Initialize the windspeed sensor."""
|
"""Initialize the windspeed sensor."""
|
||||||
super().__init__(hap, device, "Windspeed")
|
super().__init__(hap, device, post="Windspeed")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self) -> float:
|
def state(self) -> float:
|
||||||
@ -359,7 +359,7 @@ class HomematicipTodayRainSensor(HomematicipGenericEntity):
|
|||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device) -> None:
|
def __init__(self, hap: HomematicipHAP, device) -> None:
|
||||||
"""Initialize the device."""
|
"""Initialize the device."""
|
||||||
super().__init__(hap, device, "Today Rain")
|
super().__init__(hap, device, post="Today Rain")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self) -> float:
|
def state(self) -> float:
|
||||||
|
@ -54,16 +54,16 @@ async def async_setup_entry(
|
|||||||
entities.append(HomematicipSwitch(hap, device))
|
entities.append(HomematicipSwitch(hap, device))
|
||||||
elif isinstance(device, AsyncOpenCollector8Module):
|
elif isinstance(device, AsyncOpenCollector8Module):
|
||||||
for channel in range(1, 9):
|
for channel in range(1, 9):
|
||||||
entities.append(HomematicipMultiSwitch(hap, device, channel))
|
entities.append(HomematicipMultiSwitch(hap, device, channel=channel))
|
||||||
elif isinstance(device, AsyncHeatingSwitch2):
|
elif isinstance(device, AsyncHeatingSwitch2):
|
||||||
for channel in range(1, 3):
|
for channel in range(1, 3):
|
||||||
entities.append(HomematicipMultiSwitch(hap, device, channel))
|
entities.append(HomematicipMultiSwitch(hap, device, channel=channel))
|
||||||
elif isinstance(device, AsyncMultiIOBox):
|
elif isinstance(device, AsyncMultiIOBox):
|
||||||
for channel in range(1, 3):
|
for channel in range(1, 3):
|
||||||
entities.append(HomematicipMultiSwitch(hap, device, channel))
|
entities.append(HomematicipMultiSwitch(hap, device, channel=channel))
|
||||||
elif isinstance(device, AsyncPrintedCircuitBoardSwitch2):
|
elif isinstance(device, AsyncPrintedCircuitBoardSwitch2):
|
||||||
for channel in range(1, 3):
|
for channel in range(1, 3):
|
||||||
entities.append(HomematicipMultiSwitch(hap, device, channel))
|
entities.append(HomematicipMultiSwitch(hap, device, channel=channel))
|
||||||
|
|
||||||
for group in hap.home.groups:
|
for group in hap.home.groups:
|
||||||
if isinstance(group, (AsyncExtendedLinkedSwitchingGroup, AsyncSwitchingGroup)):
|
if isinstance(group, (AsyncExtendedLinkedSwitchingGroup, AsyncSwitchingGroup)):
|
||||||
@ -156,31 +156,17 @@ class HomematicipMultiSwitch(HomematicipGenericEntity, SwitchEntity):
|
|||||||
|
|
||||||
def __init__(self, hap: HomematicipHAP, device, channel: int) -> None:
|
def __init__(self, hap: HomematicipHAP, device, channel: int) -> None:
|
||||||
"""Initialize the multi switch device."""
|
"""Initialize the multi switch device."""
|
||||||
self.channel = channel
|
super().__init__(hap, device, channel=channel)
|
||||||
super().__init__(hap, device, f"Channel{channel}")
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of the multi switch channel."""
|
|
||||||
label = self._get_label_by_channel(self.channel)
|
|
||||||
if label:
|
|
||||||
return label
|
|
||||||
return super().name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self) -> str:
|
|
||||||
"""Return a unique ID."""
|
|
||||||
return f"{self.__class__.__name__}_{self.post}_{self._device.id}"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return true if switch is on."""
|
"""Return true if switch is on."""
|
||||||
return self._device.functionalChannels[self.channel].on
|
return self._device.functionalChannels[self._channel].on
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs) -> None:
|
async def async_turn_on(self, **kwargs) -> None:
|
||||||
"""Turn the switch on."""
|
"""Turn the switch on."""
|
||||||
await self._device.turn_on(self.channel)
|
await self._device.turn_on(self._channel)
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs) -> None:
|
async def async_turn_off(self, **kwargs) -> None:
|
||||||
"""Turn the switch off."""
|
"""Turn the switch off."""
|
||||||
await self._device.turn_off(self.channel)
|
await self._device.turn_off(self._channel)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user