Skip to content

Commit

Permalink
Rename entity base class for HMIPC (home-assistant#39243)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ authored Aug 25, 2020
1 parent 810df38 commit 758c0ad
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 130 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/homematicip_cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
HMIPC_HAPID,
HMIPC_NAME,
)
from .device import HomematicipGenericDevice # noqa: F401
from .generic_entity import HomematicipGenericEntity # noqa: F401
from .hap import HomematicipAuth, HomematicipHAP # noqa: F401
from .services import async_setup_services, async_unload_services

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def async_setup_entry(


class HomematicipAlarmControlPanelEntity(AlarmControlPanelEntity):
"""Representation of an alarm control panel."""
"""Representation of the HomematicIP alarm control panel."""

def __init__(self, hap: HomematicipHAP) -> None:
"""Initialize the alarm control panel."""
Expand All @@ -56,7 +56,7 @@ def device_info(self) -> Dict[str, Any]:

@property
def state(self) -> str:
"""Return the state of the device."""
"""Return the state of the alarm control panel."""
# check for triggered alarm
if self._security_and_alarm.alarmActive:
return STATE_ALARM_TRIGGERED
Expand Down Expand Up @@ -98,7 +98,7 @@ async def async_added_to_hass(self) -> None:

@callback
def _async_device_changed(self, *args, **kwargs) -> None:
"""Handle device state changes."""
"""Handle entity state changes."""
# Don't update disabled entities
if self.enabled:
_LOGGER.debug("Event %s (%s)", self.name, CONST_ALARM_CONTROL_PANEL_NAME)
Expand All @@ -111,7 +111,7 @@ def _async_device_changed(self, *args, **kwargs) -> None:

@property
def name(self) -> str:
"""Return the name of the generic device."""
"""Return the name of the generic entity."""
name = CONST_ALARM_CONTROL_PANEL_NAME
if self._home.name:
name = f"{self._home.name} {name}"
Expand All @@ -124,7 +124,7 @@ def should_poll(self) -> bool:

@property
def available(self) -> bool:
"""Device available."""
"""Return if alarm control panel is available."""
return self._home.connected

@property
Expand Down
56 changes: 28 additions & 28 deletions homeassistant/components/homematicip_cloud/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType

from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericDevice
from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericEntity
from .hap import HomematicipHAP

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -131,8 +131,8 @@ async def async_setup_entry(
async_add_entities(entities)


class HomematicipAccelerationSensor(HomematicipGenericDevice, BinarySensorEntity):
"""Representation of a HomematicIP Cloud acceleration sensor."""
class HomematicipAccelerationSensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP acceleration sensor."""

@property
def device_class(self) -> str:
Expand All @@ -157,8 +157,8 @@ def device_state_attributes(self) -> Dict[str, Any]:
return state_attr


class HomematicipContactInterface(HomematicipGenericDevice, BinarySensorEntity):
"""Representation of a HomematicIP Cloud contact interface."""
class HomematicipContactInterface(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP contact interface."""

@property
def device_class(self) -> str:
Expand All @@ -173,8 +173,8 @@ def is_on(self) -> bool:
return self._device.windowState != WindowState.CLOSED


class HomematicipShutterContact(HomematicipGenericDevice, BinarySensorEntity):
"""Representation of a HomematicIP Cloud shutter contact."""
class HomematicipShutterContact(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP shutter contact."""

@property
def device_class(self) -> str:
Expand All @@ -189,8 +189,8 @@ def is_on(self) -> bool:
return self._device.windowState != WindowState.CLOSED


class HomematicipMotionDetector(HomematicipGenericDevice, BinarySensorEntity):
"""Representation of a HomematicIP Cloud motion detector."""
class HomematicipMotionDetector(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP motion detector."""

@property
def device_class(self) -> str:
Expand All @@ -203,8 +203,8 @@ def is_on(self) -> bool:
return self._device.motionDetected


class HomematicipPresenceDetector(HomematicipGenericDevice, BinarySensorEntity):
"""Representation of a HomematicIP Cloud presence detector."""
class HomematicipPresenceDetector(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP presence detector."""

@property
def device_class(self) -> str:
Expand All @@ -217,8 +217,8 @@ def is_on(self) -> bool:
return self._device.presenceDetected


class HomematicipSmokeDetector(HomematicipGenericDevice, BinarySensorEntity):
"""Representation of a HomematicIP Cloud smoke detector."""
class HomematicipSmokeDetector(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP smoke detector."""

@property
def device_class(self) -> str:
Expand All @@ -236,8 +236,8 @@ def is_on(self) -> bool:
return False


class HomematicipWaterDetector(HomematicipGenericDevice, BinarySensorEntity):
"""Representation of a HomematicIP Cloud water detector."""
class HomematicipWaterDetector(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP water detector."""

@property
def device_class(self) -> str:
Expand All @@ -250,8 +250,8 @@ def is_on(self) -> bool:
return self._device.moistureDetected or self._device.waterlevelDetected


class HomematicipStormSensor(HomematicipGenericDevice, BinarySensorEntity):
"""Representation of a HomematicIP Cloud storm sensor."""
class HomematicipStormSensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP storm sensor."""

def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize storm sensor."""
Expand All @@ -268,8 +268,8 @@ def is_on(self) -> bool:
return self._device.storm


class HomematicipRainSensor(HomematicipGenericDevice, BinarySensorEntity):
"""Representation of a HomematicIP Cloud rain sensor."""
class HomematicipRainSensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP rain sensor."""

def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize rain sensor."""
Expand All @@ -286,8 +286,8 @@ def is_on(self) -> bool:
return self._device.raining


class HomematicipSunshineSensor(HomematicipGenericDevice, BinarySensorEntity):
"""Representation of a HomematicIP Cloud sunshine sensor."""
class HomematicipSunshineSensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP sunshine sensor."""

def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize sunshine sensor."""
Expand Down Expand Up @@ -315,8 +315,8 @@ def device_state_attributes(self) -> Dict[str, Any]:
return state_attr


class HomematicipBatterySensor(HomematicipGenericDevice, BinarySensorEntity):
"""Representation of a HomematicIP Cloud low battery sensor."""
class HomematicipBatterySensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP low battery sensor."""

def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize battery sensor."""
Expand All @@ -334,9 +334,9 @@ def is_on(self) -> bool:


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:
"""Initialize pluggable mains failure surveillance sensor."""
Expand All @@ -353,8 +353,8 @@ def is_on(self) -> bool:
return not self._device.powerMainsFailure


class HomematicipSecurityZoneSensorGroup(HomematicipGenericDevice, BinarySensorEntity):
"""Representation of a HomematicIP Cloud security zone group."""
class HomematicipSecurityZoneSensorGroup(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP security zone sensor group."""

def __init__(self, hap: HomematicipHAP, device, post: str = "SecurityZone") -> None:
"""Initialize security zone group."""
Expand Down Expand Up @@ -411,7 +411,7 @@ def is_on(self) -> bool:
class HomematicipSecuritySensorGroup(
HomematicipSecurityZoneSensorGroup, BinarySensorEntity
):
"""Representation of a HomematicIP security group."""
"""Representation of the HomematicIP security group."""

def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize security group."""
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/homematicip_cloud/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.helpers.typing import HomeAssistantType

from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericDevice
from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericEntity
from .hap import HomematicipHAP

HEATING_PROFILES = {"PROFILE_1": 0, "PROFILE_2": 1, "PROFILE_3": 2}
Expand Down Expand Up @@ -57,8 +57,8 @@ async def async_setup_entry(
async_add_entities(entities)


class HomematicipHeatingGroup(HomematicipGenericDevice, ClimateEntity):
"""Representation of a HomematicIP heating group.
class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
"""Representation of the HomematicIP heating group.
Heat mode is supported for all heating devices incl. their defined profiles.
Boost is available for radiator thermostats only.
Expand Down
14 changes: 7 additions & 7 deletions homeassistant/components/homematicip_cloud/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType

from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericDevice
from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericEntity
from .hap import HomematicipHAP

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -54,8 +54,8 @@ async def async_setup_entry(
async_add_entities(entities)


class HomematicipCoverShutter(HomematicipGenericDevice, CoverEntity):
"""Representation of a HomematicIP Cloud cover shutter device."""
class HomematicipCoverShutter(HomematicipGenericEntity, CoverEntity):
"""Representation of the HomematicIP cover shutter."""

@property
def current_cover_position(self) -> int:
Expand Down Expand Up @@ -92,7 +92,7 @@ async def async_stop_cover(self, **kwargs) -> None:


class HomematicipCoverSlats(HomematicipCoverShutter, CoverEntity):
"""Representation of a HomematicIP Cloud cover slats device."""
"""Representation of the HomematicIP cover slats."""

@property
def current_cover_tilt_position(self) -> int:
Expand Down Expand Up @@ -121,8 +121,8 @@ async def async_stop_cover_tilt(self, **kwargs) -> None:
await self._device.set_shutter_stop()


class HomematicipGarageDoorModule(HomematicipGenericDevice, CoverEntity):
"""Representation of a HomematicIP Garage Door Module."""
class HomematicipGarageDoorModule(HomematicipGenericEntity, CoverEntity):
"""Representation of the HomematicIP Garage Door Module."""

@property
def current_cover_position(self) -> int:
Expand Down Expand Up @@ -154,7 +154,7 @@ async def async_stop_cover(self, **kwargs) -> None:


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:
"""Initialize switching group."""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Generic device for the HomematicIP Cloud component."""
"""Generic entity for the HomematicIP Cloud component."""
import logging
from typing import Any, Dict, Optional

Expand Down Expand Up @@ -65,11 +65,11 @@
}


class HomematicipGenericDevice(Entity):
"""Representation of an HomematicIP generic device."""
class HomematicipGenericEntity(Entity):
"""Representation of the HomematicIP generic entity."""

def __init__(self, hap: HomematicipHAP, device, post: Optional[str] = None) -> None:
"""Initialize the generic device."""
"""Initialize the generic entity."""
self._hap = hap
self._home = hap.home
self._device = device
Expand Down Expand Up @@ -117,7 +117,7 @@ def _async_device_changed(self, *args, **kwargs) -> 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
# due to a removal of the HmIP device.
Expand All @@ -127,7 +127,7 @@ async def async_will_remove_from_hass(self) -> None:
del self._hap.hmip_device_by_entity_id[self.entity_id]
await self.async_remove_from_registries()
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:
"""Remove entity/device from registry."""
Expand Down Expand Up @@ -164,7 +164,7 @@ def _async_device_removed(self, *args, **kwargs) -> None:

@property
def name(self) -> str:
"""Return the name of the generic device."""
"""Return the name of the generic entity."""
name = self._device.label
if name and self._home.name:
name = f"{self._home.name} {name}"
Expand All @@ -186,7 +186,7 @@ def should_poll(self) -> bool:

@property
def available(self) -> bool:
"""Device available."""
"""Return if entity is available."""
return not self._device.unreach

@property
Expand All @@ -205,7 +205,7 @@ def icon(self) -> Optional[str]:

@property
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 = {}

if isinstance(self._device, AsyncDevice):
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/homematicip_cloud/hap.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def async_update(self, *args, **kwargs) -> None:
Triggered when the HMIP HOME_CHANGED event has fired.
There are several occasions for this event to happen.
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
are set to unavailable.
2. We need to update home including devices and groups after a reconnect.
Expand All @@ -131,7 +131,7 @@ def async_update(self, *args, **kwargs) -> None:
elif not self._accesspoint_connected:
# Now the HOME_CHANGED event has fired indicating the access
# 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."""

job = self.hass.async_create_task(self.get_state())
Expand All @@ -140,7 +140,7 @@ def async_update(self, *args, **kwargs) -> None:

@callback
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
self.hass.async_create_task(self.async_create_entity_lazy(is_device))

Expand Down
Loading

0 comments on commit 758c0ad

Please sign in to comment.