Rename entity base class for HMIPC (#39243)

This commit is contained in:
SukramJ 2020-08-26 01:55:55 +02:00 committed by GitHub
parent 810df38f0d
commit 758c0adb5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 130 additions and 130 deletions

View File

@ -18,7 +18,7 @@ from .const import (
HMIPC_HAPID, HMIPC_HAPID,
HMIPC_NAME, HMIPC_NAME,
) )
from .device import HomematicipGenericDevice # noqa: F401 from .generic_entity import HomematicipGenericEntity # noqa: F401
from .hap import HomematicipAuth, HomematicipHAP # noqa: F401 from .hap import HomematicipAuth, HomematicipHAP # noqa: F401
from .services import async_setup_services, async_unload_services from .services import async_setup_services, async_unload_services

View File

@ -36,7 +36,7 @@ async def async_setup_entry(
class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity): class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
"""Representation of an alarm control panel.""" """Representation of the HomematicIP alarm control panel."""
def __init__(self, hap: HomematicipHAP) -> None: def __init__(self, hap: HomematicipHAP) -> None:
"""Initialize the alarm control panel.""" """Initialize the alarm control panel."""
@ -56,7 +56,7 @@ class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
@property @property
def state(self) -> str: def state(self) -> str:
"""Return the state of the device.""" """Return the state of the alarm control panel."""
# check for triggered alarm # check for triggered alarm
if self._security_and_alarm.alarmActive: if self._security_and_alarm.alarmActive:
return STATE_ALARM_TRIGGERED return STATE_ALARM_TRIGGERED
@ -98,7 +98,7 @@ class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
@callback @callback
def _async_device_changed(self, *args, **kwargs) -> None: def _async_device_changed(self, *args, **kwargs) -> None:
"""Handle device state changes.""" """Handle entity state changes."""
# Don't update disabled entities # Don't update disabled entities
if self.enabled: if self.enabled:
_LOGGER.debug("Event %s (%s)", self.name, CONST_ALARM_CONTROL_PANEL_NAME) _LOGGER.debug("Event %s (%s)", self.name, CONST_ALARM_CONTROL_PANEL_NAME)
@ -111,7 +111,7 @@ class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
@property @property
def name(self) -> str: def name(self) -> str:
"""Return the name of the generic device.""" """Return the name of the generic entity."""
name = CONST_ALARM_CONTROL_PANEL_NAME name = CONST_ALARM_CONTROL_PANEL_NAME
if self._home.name: if self._home.name:
name = f"{self._home.name} {name}" name = f"{self._home.name} {name}"
@ -124,7 +124,7 @@ class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
@property @property
def available(self) -> bool: def available(self) -> bool:
"""Device available.""" """Return if alarm control panel is available."""
return self._home.connected return self._home.connected
@property @property

View File

@ -41,7 +41,7 @@ from homeassistant.components.binary_sensor import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericDevice from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericEntity
from .hap import HomematicipHAP from .hap import HomematicipHAP
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -131,8 +131,8 @@ async def async_setup_entry(
async_add_entities(entities) async_add_entities(entities)
class HomematicipAccelerationSensor(HomematicipGenericDevice, BinarySensorEntity): class HomematicipAccelerationSensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of a HomematicIP Cloud acceleration sensor.""" """Representation of the HomematicIP acceleration sensor."""
@property @property
def device_class(self) -> str: def device_class(self) -> str:
@ -157,8 +157,8 @@ class HomematicipAccelerationSensor(HomematicipGenericDevice, BinarySensorEntity
return state_attr return state_attr
class HomematicipContactInterface(HomematicipGenericDevice, BinarySensorEntity): class HomematicipContactInterface(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of a HomematicIP Cloud contact interface.""" """Representation of the HomematicIP contact interface."""
@property @property
def device_class(self) -> str: def device_class(self) -> str:
@ -173,8 +173,8 @@ class HomematicipContactInterface(HomematicipGenericDevice, BinarySensorEntity):
return self._device.windowState != WindowState.CLOSED return self._device.windowState != WindowState.CLOSED
class HomematicipShutterContact(HomematicipGenericDevice, BinarySensorEntity): class HomematicipShutterContact(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of a HomematicIP Cloud shutter contact.""" """Representation of the HomematicIP shutter contact."""
@property @property
def device_class(self) -> str: def device_class(self) -> str:
@ -189,8 +189,8 @@ class HomematicipShutterContact(HomematicipGenericDevice, BinarySensorEntity):
return self._device.windowState != WindowState.CLOSED return self._device.windowState != WindowState.CLOSED
class HomematicipMotionDetector(HomematicipGenericDevice, BinarySensorEntity): class HomematicipMotionDetector(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of a HomematicIP Cloud motion detector.""" """Representation of the HomematicIP motion detector."""
@property @property
def device_class(self) -> str: def device_class(self) -> str:
@ -203,8 +203,8 @@ class HomematicipMotionDetector(HomematicipGenericDevice, BinarySensorEntity):
return self._device.motionDetected return self._device.motionDetected
class HomematicipPresenceDetector(HomematicipGenericDevice, BinarySensorEntity): class HomematicipPresenceDetector(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of a HomematicIP Cloud presence detector.""" """Representation of the HomematicIP presence detector."""
@property @property
def device_class(self) -> str: def device_class(self) -> str:
@ -217,8 +217,8 @@ class HomematicipPresenceDetector(HomematicipGenericDevice, BinarySensorEntity):
return self._device.presenceDetected return self._device.presenceDetected
class HomematicipSmokeDetector(HomematicipGenericDevice, BinarySensorEntity): class HomematicipSmokeDetector(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of a HomematicIP Cloud smoke detector.""" """Representation of the HomematicIP smoke detector."""
@property @property
def device_class(self) -> str: def device_class(self) -> str:
@ -236,8 +236,8 @@ class HomematicipSmokeDetector(HomematicipGenericDevice, BinarySensorEntity):
return False return False
class HomematicipWaterDetector(HomematicipGenericDevice, BinarySensorEntity): class HomematicipWaterDetector(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of a HomematicIP Cloud water detector.""" """Representation of the HomematicIP water detector."""
@property @property
def device_class(self) -> str: def device_class(self) -> str:
@ -250,8 +250,8 @@ class HomematicipWaterDetector(HomematicipGenericDevice, BinarySensorEntity):
return self._device.moistureDetected or self._device.waterlevelDetected return self._device.moistureDetected or self._device.waterlevelDetected
class HomematicipStormSensor(HomematicipGenericDevice, BinarySensorEntity): class HomematicipStormSensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of a HomematicIP Cloud storm sensor.""" """Representation of the HomematicIP storm sensor."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize storm sensor.""" """Initialize storm sensor."""
@ -268,8 +268,8 @@ class HomematicipStormSensor(HomematicipGenericDevice, BinarySensorEntity):
return self._device.storm return self._device.storm
class HomematicipRainSensor(HomematicipGenericDevice, BinarySensorEntity): class HomematicipRainSensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of a HomematicIP Cloud rain sensor.""" """Representation of the HomematicIP rain sensor."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize rain sensor.""" """Initialize rain sensor."""
@ -286,8 +286,8 @@ class HomematicipRainSensor(HomematicipGenericDevice, BinarySensorEntity):
return self._device.raining return self._device.raining
class HomematicipSunshineSensor(HomematicipGenericDevice, BinarySensorEntity): class HomematicipSunshineSensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of a HomematicIP Cloud sunshine sensor.""" """Representation of the HomematicIP sunshine sensor."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize sunshine sensor.""" """Initialize sunshine sensor."""
@ -315,8 +315,8 @@ class HomematicipSunshineSensor(HomematicipGenericDevice, BinarySensorEntity):
return state_attr return state_attr
class HomematicipBatterySensor(HomematicipGenericDevice, BinarySensorEntity): class HomematicipBatterySensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of a HomematicIP Cloud low battery sensor.""" """Representation of the HomematicIP low battery sensor."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize battery sensor.""" """Initialize battery sensor."""
@ -334,9 +334,9 @@ class HomematicipBatterySensor(HomematicipGenericDevice, BinarySensorEntity):
class HomematicipPluggableMainsFailureSurveillanceSensor( class HomematicipPluggableMainsFailureSurveillanceSensor(
HomematicipGenericDevice, BinarySensorEntity HomematicipGenericEntity, BinarySensorEntity
): ):
"""Representation of a HomematicIP Cloud pluggable mains failure surveillance sensor.""" """Representation of the HomematicIP pluggable mains failure surveillance sensor."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize pluggable mains failure surveillance sensor.""" """Initialize pluggable mains failure surveillance sensor."""
@ -353,8 +353,8 @@ class HomematicipPluggableMainsFailureSurveillanceSensor(
return not self._device.powerMainsFailure return not self._device.powerMainsFailure
class HomematicipSecurityZoneSensorGroup(HomematicipGenericDevice, BinarySensorEntity): class HomematicipSecurityZoneSensorGroup(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of a HomematicIP Cloud security zone group.""" """Representation of the HomematicIP security zone sensor group."""
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."""
@ -411,7 +411,7 @@ class HomematicipSecurityZoneSensorGroup(HomematicipGenericDevice, BinarySensorE
class HomematicipSecuritySensorGroup( class HomematicipSecuritySensorGroup(
HomematicipSecurityZoneSensorGroup, BinarySensorEntity HomematicipSecurityZoneSensorGroup, BinarySensorEntity
): ):
"""Representation of a HomematicIP security group.""" """Representation of the HomematicIP security group."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize security group.""" """Initialize security group."""

View File

@ -27,7 +27,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericDevice from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericEntity
from .hap import HomematicipHAP from .hap import HomematicipHAP
HEATING_PROFILES = {"PROFILE_1": 0, "PROFILE_2": 1, "PROFILE_3": 2} HEATING_PROFILES = {"PROFILE_1": 0, "PROFILE_2": 1, "PROFILE_3": 2}
@ -57,8 +57,8 @@ async def async_setup_entry(
async_add_entities(entities) async_add_entities(entities)
class HomematicipHeatingGroup(HomematicipGenericDevice, ClimateEntity): class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
"""Representation of a HomematicIP heating group. """Representation of the HomematicIP heating group.
Heat mode is supported for all heating devices incl. their defined profiles. Heat mode is supported for all heating devices incl. their defined profiles.
Boost is available for radiator thermostats only. Boost is available for radiator thermostats only.

View File

@ -19,7 +19,7 @@ from homeassistant.components.cover import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericDevice from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericEntity
from .hap import HomematicipHAP from .hap import HomematicipHAP
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -54,8 +54,8 @@ async def async_setup_entry(
async_add_entities(entities) async_add_entities(entities)
class HomematicipCoverShutter(HomematicipGenericDevice, CoverEntity): class HomematicipCoverShutter(HomematicipGenericEntity, CoverEntity):
"""Representation of a HomematicIP Cloud cover shutter device.""" """Representation of the HomematicIP cover shutter."""
@property @property
def current_cover_position(self) -> int: def current_cover_position(self) -> int:
@ -92,7 +92,7 @@ class HomematicipCoverShutter(HomematicipGenericDevice, CoverEntity):
class HomematicipCoverSlats(HomematicipCoverShutter, CoverEntity): class HomematicipCoverSlats(HomematicipCoverShutter, CoverEntity):
"""Representation of a HomematicIP Cloud cover slats device.""" """Representation of the HomematicIP cover slats."""
@property @property
def current_cover_tilt_position(self) -> int: def current_cover_tilt_position(self) -> int:
@ -121,8 +121,8 @@ class HomematicipCoverSlats(HomematicipCoverShutter, CoverEntity):
await self._device.set_shutter_stop() await self._device.set_shutter_stop()
class HomematicipGarageDoorModule(HomematicipGenericDevice, CoverEntity): class HomematicipGarageDoorModule(HomematicipGenericEntity, CoverEntity):
"""Representation of a HomematicIP Garage Door Module.""" """Representation of the HomematicIP Garage Door Module."""
@property @property
def current_cover_position(self) -> int: def current_cover_position(self) -> int:
@ -154,7 +154,7 @@ class HomematicipGarageDoorModule(HomematicipGenericDevice, CoverEntity):
class HomematicipCoverShutterGroup(HomematicipCoverSlats, CoverEntity): class HomematicipCoverShutterGroup(HomematicipCoverSlats, CoverEntity):
"""Representation of a HomematicIP Cloud cover shutter group.""" """Representation of the HomematicIP cover shutter group."""
def __init__(self, hap: HomematicipHAP, device, post: str = "ShutterGroup") -> None: def __init__(self, hap: HomematicipHAP, device, post: str = "ShutterGroup") -> None:
"""Initialize switching group.""" """Initialize switching group."""

View File

@ -1,4 +1,4 @@
"""Generic device for the HomematicIP Cloud component.""" """Generic entity for the HomematicIP Cloud component."""
import logging import logging
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
@ -65,11 +65,11 @@ GROUP_ATTRIBUTES = {
} }
class HomematicipGenericDevice(Entity): class HomematicipGenericEntity(Entity):
"""Representation of an HomematicIP generic device.""" """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) -> None:
"""Initialize the generic device.""" """Initialize the generic entity."""
self._hap = hap self._hap = hap
self._home = hap.home self._home = hap.home
self._device = device self._device = device
@ -117,7 +117,7 @@ class HomematicipGenericDevice(Entity):
) )
async def async_will_remove_from_hass(self) -> None: async def async_will_remove_from_hass(self) -> None:
"""Run when entity will be removed from hass.""" """Run when hmip device will be removed from hass."""
# Only go further if the device/entity should be removed from registries # Only go further if the device/entity should be removed from registries
# due to a removal of the HmIP device. # due to a removal of the HmIP device.
@ -127,7 +127,7 @@ class HomematicipGenericDevice(Entity):
del self._hap.hmip_device_by_entity_id[self.entity_id] del self._hap.hmip_device_by_entity_id[self.entity_id]
await self.async_remove_from_registries() await self.async_remove_from_registries()
except KeyError as err: except KeyError as err:
_LOGGER.debug("Error removing HMIP entity from registry: %s", err) _LOGGER.debug("Error removing HMIP device from registry: %s", err)
async def async_remove_from_registries(self) -> None: async def async_remove_from_registries(self) -> None:
"""Remove entity/device from registry.""" """Remove entity/device from registry."""
@ -164,7 +164,7 @@ class HomematicipGenericDevice(Entity):
@property @property
def name(self) -> str: def name(self) -> str:
"""Return the name of the generic device.""" """Return the name of the generic entity."""
name = self._device.label name = self._device.label
if name and self._home.name: if name and self._home.name:
name = f"{self._home.name} {name}" name = f"{self._home.name} {name}"
@ -186,7 +186,7 @@ class HomematicipGenericDevice(Entity):
@property @property
def available(self) -> bool: def available(self) -> bool:
"""Device available.""" """Return if entity is available."""
return not self._device.unreach return not self._device.unreach
@property @property
@ -205,7 +205,7 @@ class HomematicipGenericDevice(Entity):
@property @property
def device_state_attributes(self) -> Dict[str, Any]: def device_state_attributes(self) -> Dict[str, Any]:
"""Return the state attributes of the generic device.""" """Return the state attributes of the generic entity."""
state_attr = {} state_attr = {}
if isinstance(self._device, AsyncDevice): if isinstance(self._device, AsyncDevice):

View File

@ -117,7 +117,7 @@ class HomematicipHAP:
Triggered when the HMIP HOME_CHANGED event has fired. Triggered when the HMIP HOME_CHANGED event has fired.
There are several occasions for this event to happen. There are several occasions for this event to happen.
1. We are interested to check whether the access point 1. We are interested to check whether the access point
is still connected. If not, device state changes cannot is still connected. If not, entity state changes cannot
be forwarded to hass. So if access point is disconnected all devices be forwarded to hass. So if access point is disconnected all devices
are set to unavailable. are set to unavailable.
2. We need to update home including devices and groups after a reconnect. 2. We need to update home including devices and groups after a reconnect.
@ -131,7 +131,7 @@ class HomematicipHAP:
elif not self._accesspoint_connected: elif not self._accesspoint_connected:
# Now the HOME_CHANGED event has fired indicating the access # Now the HOME_CHANGED event has fired indicating the access
# point has reconnected to the cloud again. # point has reconnected to the cloud again.
# Explicitly getting an update as device states might have # Explicitly getting an update as entity states might have
# changed during access point disconnect.""" # changed during access point disconnect."""
job = self.hass.async_create_task(self.get_state()) job = self.hass.async_create_task(self.get_state())
@ -140,7 +140,7 @@ class HomematicipHAP:
@callback @callback
def async_create_entity(self, *args, **kwargs) -> None: def async_create_entity(self, *args, **kwargs) -> None:
"""Create a device or a group.""" """Create an entity or a group."""
is_device = EventType(kwargs["event_type"]) == EventType.DEVICE_ADDED is_device = EventType(kwargs["event_type"]) == EventType.DEVICE_ADDED
self.hass.async_create_task(self.async_create_entity_lazy(is_device)) self.hass.async_create_task(self.async_create_entity_lazy(is_device))

View File

@ -26,7 +26,7 @@ from homeassistant.components.light import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericDevice from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericEntity
from .hap import HomematicipHAP from .hap import HomematicipHAP
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -64,11 +64,11 @@ async def async_setup_entry(
async_add_entities(entities) async_add_entities(entities)
class HomematicipLight(HomematicipGenericDevice, LightEntity): class HomematicipLight(HomematicipGenericEntity, LightEntity):
"""Representation of a HomematicIP Cloud light device.""" """Representation of the HomematicIP light."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the light device.""" """Initialize the light entity."""
super().__init__(hap, device) super().__init__(hap, device)
@property @property
@ -81,24 +81,24 @@ class HomematicipLight(HomematicipGenericDevice, LightEntity):
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if device is on.""" """Return true if light is on."""
return self._device.on return self._device.on
async def async_turn_on(self, **kwargs) -> None: async def async_turn_on(self, **kwargs) -> None:
"""Turn the device on.""" """Turn the light on."""
await self._device.turn_on() await self._device.turn_on()
async def async_turn_off(self, **kwargs) -> None: async def async_turn_off(self, **kwargs) -> None:
"""Turn the device off.""" """Turn the light off."""
await self._device.turn_off() await self._device.turn_off()
class HomematicipLightMeasuring(HomematicipLight): class HomematicipLightMeasuring(HomematicipLight):
"""Representation of a HomematicIP Cloud measuring light device.""" """Representation of the HomematicIP measuring light."""
@property @property
def device_state_attributes(self) -> Dict[str, Any]: def device_state_attributes(self) -> Dict[str, Any]:
"""Return the state attributes of the generic device.""" """Return the state attributes of the light."""
state_attr = super().device_state_attributes state_attr = super().device_state_attributes
current_power_w = self._device.currentPowerConsumption current_power_w = self._device.currentPowerConsumption
@ -110,16 +110,16 @@ class HomematicipLightMeasuring(HomematicipLight):
return state_attr return state_attr
class HomematicipDimmer(HomematicipGenericDevice, LightEntity): class HomematicipDimmer(HomematicipGenericEntity, LightEntity):
"""Representation of HomematicIP Cloud dimmer light device.""" """Representation of HomematicIP Cloud dimmer."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the dimmer light device.""" """Initialize the dimmer light entity."""
super().__init__(hap, device) super().__init__(hap, device)
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if device is on.""" """Return true if dimmer is on."""
return self._device.dimLevel is not None and self._device.dimLevel > 0.0 return self._device.dimLevel is not None and self._device.dimLevel > 0.0
@property @property
@ -133,22 +133,22 @@ class HomematicipDimmer(HomematicipGenericDevice, LightEntity):
return SUPPORT_BRIGHTNESS return SUPPORT_BRIGHTNESS
async def async_turn_on(self, **kwargs) -> None: async def async_turn_on(self, **kwargs) -> None:
"""Turn the light on.""" """Turn the dimmer on."""
if ATTR_BRIGHTNESS in kwargs: if ATTR_BRIGHTNESS in kwargs:
await self._device.set_dim_level(kwargs[ATTR_BRIGHTNESS] / 255.0) await self._device.set_dim_level(kwargs[ATTR_BRIGHTNESS] / 255.0)
else: else:
await self._device.set_dim_level(1) await self._device.set_dim_level(1)
async def async_turn_off(self, **kwargs) -> None: async def async_turn_off(self, **kwargs) -> None:
"""Turn the light off.""" """Turn the dimmer off."""
await self._device.set_dim_level(0) await self._device.set_dim_level(0)
class HomematicipNotificationLight(HomematicipGenericDevice, LightEntity): class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
"""Representation of HomematicIP Cloud dimmer light device.""" """Representation of HomematicIP Cloud notification light."""
def __init__(self, hap: HomematicipHAP, device, channel: int) -> None: def __init__(self, hap: HomematicipHAP, device, channel: int) -> None:
"""Initialize the dimmer light device.""" """Initialize the notification light entity."""
self.channel = channel self.channel = channel
if self.channel == 2: if self.channel == 2:
super().__init__(hap, device, "Top") super().__init__(hap, device, "Top")
@ -171,7 +171,7 @@ class HomematicipNotificationLight(HomematicipGenericDevice, LightEntity):
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if device is on.""" """Return true if light is on."""
return ( return (
self._func_channel.dimLevel is not None self._func_channel.dimLevel is not None
and self._func_channel.dimLevel > 0.0 and self._func_channel.dimLevel > 0.0
@ -190,7 +190,7 @@ class HomematicipNotificationLight(HomematicipGenericDevice, LightEntity):
@property @property
def device_state_attributes(self) -> Dict[str, Any]: def device_state_attributes(self) -> Dict[str, Any]:
"""Return the state attributes of the generic device.""" """Return the state attributes of the notification light sensor."""
state_attr = super().device_state_attributes state_attr = super().device_state_attributes
if self.is_on: if self.is_on:
@ -200,7 +200,7 @@ class HomematicipNotificationLight(HomematicipGenericDevice, LightEntity):
@property @property
def name(self) -> str: def name(self) -> str:
"""Return the name of the generic device.""" """Return the name of the notification light sensor."""
label = self._get_label_by_channel(self.channel) label = self._get_label_by_channel(self.channel)
if label: if label:
return label return label

View File

@ -37,8 +37,8 @@ from homeassistant.const import (
) )
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericDevice from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericEntity
from .device import ATTR_IS_GROUP, ATTR_MODEL_TYPE from .generic_entity import ATTR_IS_GROUP, ATTR_MODEL_TYPE
from .hap import HomematicipHAP from .hap import HomematicipHAP
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -120,11 +120,11 @@ async def async_setup_entry(
async_add_entities(entities) async_add_entities(entities)
class HomematicipAccesspointStatus(HomematicipGenericDevice): class HomematicipAccesspointStatus(HomematicipGenericEntity):
"""Representation of an HomeMaticIP Cloud access point.""" """Representation of then HomeMaticIP access point."""
def __init__(self, hap: HomematicipHAP) -> None: def __init__(self, hap: HomematicipHAP) -> None:
"""Initialize access point device.""" """Initialize access point status entity."""
super().__init__(hap, hap.home) super().__init__(hap, hap.home)
@property @property
@ -140,7 +140,7 @@ class HomematicipAccesspointStatus(HomematicipGenericDevice):
@property @property
def icon(self) -> str: def icon(self) -> str:
"""Return the icon of the access point device.""" """Return the icon of the access point entity."""
return "mdi:access-point-network" return "mdi:access-point-network"
@property @property
@ -150,7 +150,7 @@ class HomematicipAccesspointStatus(HomematicipGenericDevice):
@property @property
def available(self) -> bool: def available(self) -> bool:
"""Device available.""" """Return if access point is available."""
return self._home.connected return self._home.connected
@property @property
@ -169,8 +169,8 @@ class HomematicipAccesspointStatus(HomematicipGenericDevice):
return state_attr return state_attr
class HomematicipHeatingThermostat(HomematicipGenericDevice): class HomematicipHeatingThermostat(HomematicipGenericEntity):
"""Representation of a HomematicIP heating thermostat device.""" """Representation of the HomematicIP heating thermostat."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize heating thermostat device.""" """Initialize heating thermostat device."""
@ -198,8 +198,8 @@ class HomematicipHeatingThermostat(HomematicipGenericDevice):
return UNIT_PERCENTAGE return UNIT_PERCENTAGE
class HomematicipHumiditySensor(HomematicipGenericDevice): class HomematicipHumiditySensor(HomematicipGenericEntity):
"""Representation of a HomematicIP Cloud humidity device.""" """Representation of the HomematicIP humidity sensor."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the thermometer device.""" """Initialize the thermometer device."""
@ -221,8 +221,8 @@ class HomematicipHumiditySensor(HomematicipGenericDevice):
return UNIT_PERCENTAGE return UNIT_PERCENTAGE
class HomematicipTemperatureSensor(HomematicipGenericDevice): class HomematicipTemperatureSensor(HomematicipGenericEntity):
"""Representation of a HomematicIP Cloud thermometer device.""" """Representation of the HomematicIP thermometer."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the thermometer device.""" """Initialize the thermometer device."""
@ -258,8 +258,8 @@ class HomematicipTemperatureSensor(HomematicipGenericDevice):
return state_attr return state_attr
class HomematicipIlluminanceSensor(HomematicipGenericDevice): class HomematicipIlluminanceSensor(HomematicipGenericEntity):
"""Representation of a HomematicIP Illuminance device.""" """Representation of the HomematicIP Illuminance sensor."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the device.""" """Initialize the device."""
@ -296,8 +296,8 @@ class HomematicipIlluminanceSensor(HomematicipGenericDevice):
return state_attr return state_attr
class HomematicipPowerSensor(HomematicipGenericDevice): class HomematicipPowerSensor(HomematicipGenericEntity):
"""Representation of a HomematicIP power measuring device.""" """Representation of the HomematicIP power measuring sensor."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the device.""" """Initialize the device."""
@ -310,7 +310,7 @@ class HomematicipPowerSensor(HomematicipGenericDevice):
@property @property
def state(self) -> float: def state(self) -> float:
"""Representation of the HomematicIP power consumption value.""" """Return the power consumption value."""
return self._device.currentPowerConsumption return self._device.currentPowerConsumption
@property @property
@ -319,16 +319,16 @@ class HomematicipPowerSensor(HomematicipGenericDevice):
return POWER_WATT return POWER_WATT
class HomematicipWindspeedSensor(HomematicipGenericDevice): class HomematicipWindspeedSensor(HomematicipGenericEntity):
"""Representation of a HomematicIP wind speed sensor.""" """Representation of the HomematicIP wind speed sensor."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the device.""" """Initialize the windspeed sensor."""
super().__init__(hap, device, "Windspeed") super().__init__(hap, device, "Windspeed")
@property @property
def state(self) -> float: def state(self) -> float:
"""Representation of the HomematicIP wind speed value.""" """Return the wind speed value."""
return self._device.windSpeed return self._device.windSpeed
@property @property
@ -352,8 +352,8 @@ class HomematicipWindspeedSensor(HomematicipGenericDevice):
return state_attr return state_attr
class HomematicipTodayRainSensor(HomematicipGenericDevice): class HomematicipTodayRainSensor(HomematicipGenericEntity):
"""Representation of a HomematicIP rain counter of a day sensor.""" """Representation of the HomematicIP rain counter of a day sensor."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the device.""" """Initialize the device."""
@ -361,7 +361,7 @@ class HomematicipTodayRainSensor(HomematicipGenericDevice):
@property @property
def state(self) -> float: def state(self) -> float:
"""Representation of the HomematicIP today's rain value.""" """Return the today's rain value."""
return round(self._device.todayRainCounter, 2) return round(self._device.todayRainCounter, 2)
@property @property
@ -370,12 +370,12 @@ class HomematicipTodayRainSensor(HomematicipGenericDevice):
return "mm" return "mm"
class HomematicipPassageDetectorDeltaCounter(HomematicipGenericDevice): class HomematicipPassageDetectorDeltaCounter(HomematicipGenericEntity):
"""Representation of a HomematicIP passage detector delta counter.""" """Representation of the HomematicIP passage detector delta counter."""
@property @property
def state(self) -> int: def state(self) -> int:
"""Representation of the HomematicIP passage detector delta counter value.""" """Return the passage detector delta counter value."""
return self._device.leftRightCounterDelta return self._device.leftRightCounterDelta
@property @property

View File

@ -20,8 +20,8 @@ from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericDevice from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericEntity
from .device import ATTR_GROUP_MEMBER_UNREACHABLE from .generic_entity import ATTR_GROUP_MEMBER_UNREACHABLE
from .hap import HomematicipHAP from .hap import HomematicipHAP
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -36,7 +36,7 @@ async def async_setup_entry(
for device in hap.home.devices: for device in hap.home.devices:
if isinstance(device, AsyncBrandSwitchMeasuring): if isinstance(device, AsyncBrandSwitchMeasuring):
# BrandSwitchMeasuring inherits PlugableSwitchMeasuring # BrandSwitchMeasuring inherits PlugableSwitchMeasuring
# This device is implemented in the light platform and will # This entity is implemented in the light platform and will
# not be added in the switch platform # not be added in the switch platform
pass pass
elif isinstance( elif isinstance(
@ -73,8 +73,8 @@ async def async_setup_entry(
async_add_entities(entities) async_add_entities(entities)
class HomematicipSwitch(HomematicipGenericDevice, SwitchEntity): class HomematicipSwitch(HomematicipGenericEntity, SwitchEntity):
"""representation of a HomematicIP Cloud switch device.""" """Representation of the HomematicIP switch."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the switch device.""" """Initialize the switch device."""
@ -94,8 +94,8 @@ class HomematicipSwitch(HomematicipGenericDevice, SwitchEntity):
await self._device.turn_off() await self._device.turn_off()
class HomematicipGroupSwitch(HomematicipGenericDevice, SwitchEntity): class HomematicipGroupSwitch(HomematicipGenericEntity, SwitchEntity):
"""representation of a HomematicIP switching group.""" """Representation of the HomematicIP switching group."""
def __init__(self, hap: HomematicipHAP, device, post: str = "Group") -> None: def __init__(self, hap: HomematicipHAP, device, post: str = "Group") -> None:
"""Initialize switching group.""" """Initialize switching group."""
@ -136,7 +136,7 @@ class HomematicipGroupSwitch(HomematicipGenericDevice, SwitchEntity):
class HomematicipSwitchMeasuring(HomematicipSwitch): class HomematicipSwitchMeasuring(HomematicipSwitch):
"""Representation of a HomematicIP measuring switch device.""" """Representation of the HomematicIP measuring switch."""
@property @property
def current_power_w(self) -> float: def current_power_w(self) -> float:
@ -151,8 +151,8 @@ class HomematicipSwitchMeasuring(HomematicipSwitch):
return round(self._device.energyCounter) return round(self._device.energyCounter)
class HomematicipMultiSwitch(HomematicipGenericDevice, SwitchEntity): class HomematicipMultiSwitch(HomematicipGenericEntity, SwitchEntity):
"""Representation of a HomematicIP Cloud multi switch device.""" """Representation of the HomematicIP multi switch."""
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."""
@ -174,13 +174,13 @@ class HomematicipMultiSwitch(HomematicipGenericDevice, SwitchEntity):
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if device 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 device 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 device off.""" """Turn the switch off."""
await self._device.turn_off(self.channel) await self._device.turn_off(self.channel)

View File

@ -13,7 +13,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericDevice from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericEntity
from .hap import HomematicipHAP from .hap import HomematicipHAP
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -55,8 +55,8 @@ async def async_setup_entry(
async_add_entities(entities) async_add_entities(entities)
class HomematicipWeatherSensor(HomematicipGenericDevice, WeatherEntity): class HomematicipWeatherSensor(HomematicipGenericEntity, WeatherEntity):
"""representation of a HomematicIP Cloud weather sensor plus & basic.""" """Representation of the HomematicIP weather sensor plus & basic."""
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the weather sensor.""" """Initialize the weather sensor."""
@ -105,7 +105,7 @@ class HomematicipWeatherSensor(HomematicipGenericDevice, WeatherEntity):
class HomematicipWeatherSensorPro(HomematicipWeatherSensor): class HomematicipWeatherSensorPro(HomematicipWeatherSensor):
"""representation of a HomematicIP weather sensor pro.""" """Representation of the HomematicIP weather sensor pro."""
@property @property
def wind_bearing(self) -> float: def wind_bearing(self) -> float:
@ -113,8 +113,8 @@ class HomematicipWeatherSensorPro(HomematicipWeatherSensor):
return self._device.windDirection return self._device.windDirection
class HomematicipHomeWeather(HomematicipGenericDevice, WeatherEntity): class HomematicipHomeWeather(HomematicipGenericEntity, WeatherEntity):
"""representation of a HomematicIP Cloud home weather.""" """Representation of the HomematicIP home weather."""
def __init__(self, hap: HomematicipHAP) -> None: def __init__(self, hap: HomematicipHAP) -> None:
"""Initialize the home weather.""" """Initialize the home weather."""
@ -123,7 +123,7 @@ class HomematicipHomeWeather(HomematicipGenericDevice, WeatherEntity):
@property @property
def available(self) -> bool: def available(self) -> bool:
"""Device available.""" """Return if weather entity is available."""
return self._home.connected return self._home.connected
@property @property
@ -133,7 +133,7 @@ class HomematicipHomeWeather(HomematicipGenericDevice, WeatherEntity):
@property @property
def temperature(self) -> float: def temperature(self) -> float:
"""Return the platform temperature.""" """Return the temperature."""
return self._device.weather.temperature return self._device.weather.temperature
@property @property

View File

@ -13,7 +13,7 @@ from homematicip.home import Home
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.homematicip_cloud.device import ( from homeassistant.components.homematicip_cloud.generic_entity import (
ATTR_IS_GROUP, ATTR_IS_GROUP,
ATTR_MODEL_TYPE, ATTR_MODEL_TYPE,
) )

View File

@ -15,7 +15,7 @@ from homeassistant.components.homematicip_cloud.binary_sensor import (
ATTR_WATER_LEVEL_DETECTED, ATTR_WATER_LEVEL_DETECTED,
ATTR_WINDOW_STATE, ATTR_WINDOW_STATE,
) )
from homeassistant.components.homematicip_cloud.device import ( from homeassistant.components.homematicip_cloud.generic_entity import (
ATTR_EVENT_DELAY, ATTR_EVENT_DELAY,
ATTR_GROUP_MEMBER_UNREACHABLE, ATTR_GROUP_MEMBER_UNREACHABLE,
ATTR_LOW_BATTERY, ATTR_LOW_BATTERY,

View File

@ -2,7 +2,7 @@
from homematicip.base.enums import ValveState from homematicip.base.enums import ValveState
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.homematicip_cloud.device import ( from homeassistant.components.homematicip_cloud.generic_entity import (
ATTR_CONFIG_PENDING, ATTR_CONFIG_PENDING,
ATTR_DEVICE_OVERHEATED, ATTR_DEVICE_OVERHEATED,
ATTR_DEVICE_OVERLOADED, ATTR_DEVICE_OVERLOADED,

View File

@ -1,6 +1,6 @@
"""Tests for HomematicIP Cloud switch.""" """Tests for HomematicIP Cloud switch."""
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.homematicip_cloud.device import ( from homeassistant.components.homematicip_cloud.generic_entity import (
ATTR_GROUP_MEMBER_UNREACHABLE, ATTR_GROUP_MEMBER_UNREACHABLE,
) )
from homeassistant.components.switch import ( from homeassistant.components.switch import (