Use more shorthand properties in homematicip_cloud (#100210)

This commit is contained in:
J. Nick Koston 2023-09-12 12:45:53 -05:00 committed by GitHub
parent 6a7d5a0fd4
commit 42c35da818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 84 deletions

View File

@ -194,10 +194,7 @@ class HomematicipCloudConnectionSensor(HomematicipGenericEntity, BinarySensorEnt
class HomematicipBaseActionSensor(HomematicipGenericEntity, BinarySensorEntity): class HomematicipBaseActionSensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP base action sensor.""" """Representation of the HomematicIP base action sensor."""
@property _attr_device_class = BinarySensorDeviceClass.MOVING
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this sensor."""
return BinarySensorDeviceClass.MOVING
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
@ -227,6 +224,8 @@ class HomematicipTiltVibrationSensor(HomematicipBaseActionSensor):
class HomematicipMultiContactInterface(HomematicipGenericEntity, BinarySensorEntity): class HomematicipMultiContactInterface(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP multi room/area contact interface.""" """Representation of the HomematicIP multi room/area contact interface."""
_attr_device_class = BinarySensorDeviceClass.OPENING
def __init__( def __init__(
self, self,
hap: HomematicipHAP, hap: HomematicipHAP,
@ -239,11 +238,6 @@ class HomematicipMultiContactInterface(HomematicipGenericEntity, BinarySensorEnt
hap, device, channel=channel, is_multi_channel=is_multi_channel hap, device, channel=channel, is_multi_channel=is_multi_channel
) )
@property
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this sensor."""
return BinarySensorDeviceClass.OPENING
@property @property
def is_on(self) -> bool | None: def is_on(self) -> bool | None:
"""Return true if the contact interface is on/open.""" """Return true if the contact interface is on/open."""
@ -266,6 +260,8 @@ class HomematicipContactInterface(HomematicipMultiContactInterface, BinarySensor
class HomematicipShutterContact(HomematicipMultiContactInterface, BinarySensorEntity): class HomematicipShutterContact(HomematicipMultiContactInterface, BinarySensorEntity):
"""Representation of the HomematicIP shutter contact.""" """Representation of the HomematicIP shutter contact."""
_attr_device_class = BinarySensorDeviceClass.DOOR
def __init__( def __init__(
self, hap: HomematicipHAP, device, has_additional_state: bool = False self, hap: HomematicipHAP, device, has_additional_state: bool = False
) -> None: ) -> None:
@ -273,11 +269,6 @@ class HomematicipShutterContact(HomematicipMultiContactInterface, BinarySensorEn
super().__init__(hap, device, is_multi_channel=False) super().__init__(hap, device, is_multi_channel=False)
self.has_additional_state = has_additional_state self.has_additional_state = has_additional_state
@property
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this sensor."""
return BinarySensorDeviceClass.DOOR
@property @property
def extra_state_attributes(self) -> dict[str, Any]: def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes of the Shutter Contact.""" """Return the state attributes of the Shutter Contact."""
@ -294,10 +285,7 @@ class HomematicipShutterContact(HomematicipMultiContactInterface, BinarySensorEn
class HomematicipMotionDetector(HomematicipGenericEntity, BinarySensorEntity): class HomematicipMotionDetector(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP motion detector.""" """Representation of the HomematicIP motion detector."""
@property _attr_device_class = BinarySensorDeviceClass.MOTION
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this sensor."""
return BinarySensorDeviceClass.MOTION
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
@ -308,10 +296,7 @@ class HomematicipMotionDetector(HomematicipGenericEntity, BinarySensorEntity):
class HomematicipPresenceDetector(HomematicipGenericEntity, BinarySensorEntity): class HomematicipPresenceDetector(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP presence detector.""" """Representation of the HomematicIP presence detector."""
@property _attr_device_class = BinarySensorDeviceClass.PRESENCE
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this sensor."""
return BinarySensorDeviceClass.PRESENCE
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
@ -322,10 +307,7 @@ class HomematicipPresenceDetector(HomematicipGenericEntity, BinarySensorEntity):
class HomematicipSmokeDetector(HomematicipGenericEntity, BinarySensorEntity): class HomematicipSmokeDetector(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP smoke detector.""" """Representation of the HomematicIP smoke detector."""
@property _attr_device_class = BinarySensorDeviceClass.SMOKE
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this sensor."""
return BinarySensorDeviceClass.SMOKE
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
@ -341,10 +323,7 @@ class HomematicipSmokeDetector(HomematicipGenericEntity, BinarySensorEntity):
class HomematicipWaterDetector(HomematicipGenericEntity, BinarySensorEntity): class HomematicipWaterDetector(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP water detector.""" """Representation of the HomematicIP water detector."""
@property _attr_device_class = BinarySensorDeviceClass.MOISTURE
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this sensor."""
return BinarySensorDeviceClass.MOISTURE
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
@ -373,15 +352,12 @@ class HomematicipStormSensor(HomematicipGenericEntity, BinarySensorEntity):
class HomematicipRainSensor(HomematicipGenericEntity, BinarySensorEntity): class HomematicipRainSensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP rain sensor.""" """Representation of the HomematicIP rain sensor."""
_attr_device_class = BinarySensorDeviceClass.MOISTURE
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize rain sensor.""" """Initialize rain sensor."""
super().__init__(hap, device, "Raining") super().__init__(hap, device, "Raining")
@property
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this sensor."""
return BinarySensorDeviceClass.MOISTURE
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true, if it is raining.""" """Return true, if it is raining."""
@ -391,15 +367,12 @@ class HomematicipRainSensor(HomematicipGenericEntity, BinarySensorEntity):
class HomematicipSunshineSensor(HomematicipGenericEntity, BinarySensorEntity): class HomematicipSunshineSensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP sunshine sensor.""" """Representation of the HomematicIP sunshine sensor."""
_attr_device_class = BinarySensorDeviceClass.LIGHT
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize sunshine sensor.""" """Initialize sunshine sensor."""
super().__init__(hap, device, post="Sunshine") super().__init__(hap, device, post="Sunshine")
@property
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this sensor."""
return BinarySensorDeviceClass.LIGHT
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if sun is shining.""" """Return true if sun is shining."""
@ -420,15 +393,12 @@ class HomematicipSunshineSensor(HomematicipGenericEntity, BinarySensorEntity):
class HomematicipBatterySensor(HomematicipGenericEntity, BinarySensorEntity): class HomematicipBatterySensor(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP low battery sensor.""" """Representation of the HomematicIP low battery sensor."""
_attr_device_class = BinarySensorDeviceClass.BATTERY
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize battery sensor.""" """Initialize battery sensor."""
super().__init__(hap, device, post="Battery") super().__init__(hap, device, post="Battery")
@property
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this sensor."""
return BinarySensorDeviceClass.BATTERY
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if battery is low.""" """Return true if battery is low."""
@ -440,15 +410,12 @@ class HomematicipPluggableMainsFailureSurveillanceSensor(
): ):
"""Representation of the HomematicIP pluggable mains failure surveillance sensor.""" """Representation of the HomematicIP pluggable mains failure surveillance sensor."""
_attr_device_class = BinarySensorDeviceClass.POWER
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."""
super().__init__(hap, device) super().__init__(hap, device)
@property
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this sensor."""
return BinarySensorDeviceClass.POWER
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
"""Return true if power mains fails.""" """Return true if power mains fails."""
@ -458,16 +425,13 @@ class HomematicipPluggableMainsFailureSurveillanceSensor(
class HomematicipSecurityZoneSensorGroup(HomematicipGenericEntity, BinarySensorEntity): class HomematicipSecurityZoneSensorGroup(HomematicipGenericEntity, BinarySensorEntity):
"""Representation of the HomematicIP security zone sensor group.""" """Representation of the HomematicIP security zone sensor group."""
_attr_device_class = BinarySensorDeviceClass.SAFETY
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=post) super().__init__(hap, device, post=post)
@property
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this sensor."""
return BinarySensorDeviceClass.SAFETY
@property @property
def available(self) -> bool: def available(self) -> bool:
"""Security-Group available.""" """Security-Group available."""

View File

@ -68,10 +68,7 @@ async def async_setup_entry(
class HomematicipBlindModule(HomematicipGenericEntity, CoverEntity): class HomematicipBlindModule(HomematicipGenericEntity, CoverEntity):
"""Representation of the HomematicIP blind module.""" """Representation of the HomematicIP blind module."""
@property _attr_device_class = CoverDeviceClass.BLIND
def device_class(self) -> CoverDeviceClass:
"""Return the class of the cover."""
return CoverDeviceClass.BLIND
@property @property
def current_cover_position(self) -> int | None: def current_cover_position(self) -> int | None:
@ -149,6 +146,8 @@ class HomematicipBlindModule(HomematicipGenericEntity, CoverEntity):
class HomematicipMultiCoverShutter(HomematicipGenericEntity, CoverEntity): class HomematicipMultiCoverShutter(HomematicipGenericEntity, CoverEntity):
"""Representation of the HomematicIP cover shutter.""" """Representation of the HomematicIP cover shutter."""
_attr_device_class = CoverDeviceClass.SHUTTER
def __init__( def __init__(
self, self,
hap: HomematicipHAP, hap: HomematicipHAP,
@ -161,11 +160,6 @@ class HomematicipMultiCoverShutter(HomematicipGenericEntity, CoverEntity):
hap, device, channel=channel, is_multi_channel=is_multi_channel hap, device, channel=channel, is_multi_channel=is_multi_channel
) )
@property
def device_class(self) -> CoverDeviceClass:
"""Return the class of the cover."""
return CoverDeviceClass.SHUTTER
@property @property
def current_cover_position(self) -> int | None: def current_cover_position(self) -> int | None:
"""Return current position of cover.""" """Return current position of cover."""
@ -272,6 +266,8 @@ class HomematicipCoverSlats(HomematicipMultiCoverSlats, CoverEntity):
class HomematicipGarageDoorModule(HomematicipGenericEntity, CoverEntity): class HomematicipGarageDoorModule(HomematicipGenericEntity, CoverEntity):
"""Representation of the HomematicIP Garage Door Module.""" """Representation of the HomematicIP Garage Door Module."""
_attr_device_class = CoverDeviceClass.GARAGE
@property @property
def current_cover_position(self) -> int | None: def current_cover_position(self) -> int | None:
"""Return current position of cover.""" """Return current position of cover."""
@ -283,11 +279,6 @@ class HomematicipGarageDoorModule(HomematicipGenericEntity, CoverEntity):
} }
return door_state_to_position.get(self._device.doorState) return door_state_to_position.get(self._device.doorState)
@property
def device_class(self) -> CoverDeviceClass:
"""Return the class of the cover."""
return CoverDeviceClass.GARAGE
@property @property
def is_closed(self) -> bool | None: def is_closed(self) -> bool | None:
"""Return if the cover is closed.""" """Return if the cover is closed."""
@ -309,16 +300,13 @@ class HomematicipGarageDoorModule(HomematicipGenericEntity, CoverEntity):
class HomematicipCoverShutterGroup(HomematicipGenericEntity, CoverEntity): class HomematicipCoverShutterGroup(HomematicipGenericEntity, CoverEntity):
"""Representation of the HomematicIP cover shutter group.""" """Representation of the HomematicIP cover shutter group."""
_attr_device_class = CoverDeviceClass.SHUTTER
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."""
device.modelType = f"HmIP-{post}" device.modelType = f"HmIP-{post}"
super().__init__(hap, device, post, is_multi_channel=False) super().__init__(hap, device, post, is_multi_channel=False)
@property
def device_class(self) -> CoverDeviceClass:
"""Return the class of the cover."""
return CoverDeviceClass.SHUTTER
@property @property
def current_cover_position(self) -> int | None: def current_cover_position(self) -> int | None:
"""Return current position of cover.""" """Return current position of cover."""

View File

@ -72,6 +72,7 @@ class HomematicipWeatherSensor(HomematicipGenericEntity, WeatherEntity):
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS _attr_native_temperature_unit = UnitOfTemperature.CELSIUS
_attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
_attr_attribution = "Powered by Homematic IP"
def __init__(self, hap: HomematicipHAP, device) -> None: def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the weather sensor.""" """Initialize the weather sensor."""
@ -97,11 +98,6 @@ class HomematicipWeatherSensor(HomematicipGenericEntity, WeatherEntity):
"""Return the wind speed.""" """Return the wind speed."""
return self._device.windSpeed return self._device.windSpeed
@property
def attribution(self) -> str:
"""Return the attribution."""
return "Powered by Homematic IP"
@property @property
def condition(self) -> str: def condition(self) -> str:
"""Return the current condition.""" """Return the current condition."""
@ -128,6 +124,7 @@ class HomematicipHomeWeather(HomematicipGenericEntity, WeatherEntity):
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS _attr_native_temperature_unit = UnitOfTemperature.CELSIUS
_attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
_attr_attribution = "Powered by Homematic IP"
def __init__(self, hap: HomematicipHAP) -> None: def __init__(self, hap: HomematicipHAP) -> None:
"""Initialize the home weather.""" """Initialize the home weather."""
@ -164,11 +161,6 @@ class HomematicipHomeWeather(HomematicipGenericEntity, WeatherEntity):
"""Return the wind bearing.""" """Return the wind bearing."""
return self._device.weather.windDirection return self._device.weather.windDirection
@property
def attribution(self) -> str:
"""Return the attribution."""
return "Powered by Homematic IP"
@property @property
def condition(self) -> str | None: def condition(self) -> str | None:
"""Return the current condition.""" """Return the current condition."""