From 42c35da81850570aae576898acf54729bce3e16a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 12 Sep 2023 12:45:53 -0500 Subject: [PATCH] Use more shorthand properties in homematicip_cloud (#100210) --- .../homematicip_cloud/binary_sensor.py | 74 +++++-------------- .../components/homematicip_cloud/cover.py | 26 ++----- .../components/homematicip_cloud/weather.py | 12 +-- 3 files changed, 28 insertions(+), 84 deletions(-) diff --git a/homeassistant/components/homematicip_cloud/binary_sensor.py b/homeassistant/components/homematicip_cloud/binary_sensor.py index 6730f722685..2afe803e1eb 100644 --- a/homeassistant/components/homematicip_cloud/binary_sensor.py +++ b/homeassistant/components/homematicip_cloud/binary_sensor.py @@ -194,10 +194,7 @@ class HomematicipCloudConnectionSensor(HomematicipGenericEntity, BinarySensorEnt class HomematicipBaseActionSensor(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP base action sensor.""" - @property - def device_class(self) -> BinarySensorDeviceClass: - """Return the class of this sensor.""" - return BinarySensorDeviceClass.MOVING + _attr_device_class = BinarySensorDeviceClass.MOVING @property def is_on(self) -> bool: @@ -227,6 +224,8 @@ class HomematicipTiltVibrationSensor(HomematicipBaseActionSensor): class HomematicipMultiContactInterface(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP multi room/area contact interface.""" + _attr_device_class = BinarySensorDeviceClass.OPENING + def __init__( self, hap: HomematicipHAP, @@ -239,11 +238,6 @@ class HomematicipMultiContactInterface(HomematicipGenericEntity, BinarySensorEnt 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 def is_on(self) -> bool | None: """Return true if the contact interface is on/open.""" @@ -266,6 +260,8 @@ class HomematicipContactInterface(HomematicipMultiContactInterface, BinarySensor class HomematicipShutterContact(HomematicipMultiContactInterface, BinarySensorEntity): """Representation of the HomematicIP shutter contact.""" + _attr_device_class = BinarySensorDeviceClass.DOOR + def __init__( self, hap: HomematicipHAP, device, has_additional_state: bool = False ) -> None: @@ -273,11 +269,6 @@ class HomematicipShutterContact(HomematicipMultiContactInterface, BinarySensorEn super().__init__(hap, device, is_multi_channel=False) self.has_additional_state = has_additional_state - @property - def device_class(self) -> BinarySensorDeviceClass: - """Return the class of this sensor.""" - return BinarySensorDeviceClass.DOOR - @property def extra_state_attributes(self) -> dict[str, Any]: """Return the state attributes of the Shutter Contact.""" @@ -294,10 +285,7 @@ class HomematicipShutterContact(HomematicipMultiContactInterface, BinarySensorEn class HomematicipMotionDetector(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP motion detector.""" - @property - def device_class(self) -> BinarySensorDeviceClass: - """Return the class of this sensor.""" - return BinarySensorDeviceClass.MOTION + _attr_device_class = BinarySensorDeviceClass.MOTION @property def is_on(self) -> bool: @@ -308,10 +296,7 @@ class HomematicipMotionDetector(HomematicipGenericEntity, BinarySensorEntity): class HomematicipPresenceDetector(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP presence detector.""" - @property - def device_class(self) -> BinarySensorDeviceClass: - """Return the class of this sensor.""" - return BinarySensorDeviceClass.PRESENCE + _attr_device_class = BinarySensorDeviceClass.PRESENCE @property def is_on(self) -> bool: @@ -322,10 +307,7 @@ class HomematicipPresenceDetector(HomematicipGenericEntity, BinarySensorEntity): class HomematicipSmokeDetector(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP smoke detector.""" - @property - def device_class(self) -> BinarySensorDeviceClass: - """Return the class of this sensor.""" - return BinarySensorDeviceClass.SMOKE + _attr_device_class = BinarySensorDeviceClass.SMOKE @property def is_on(self) -> bool: @@ -341,10 +323,7 @@ class HomematicipSmokeDetector(HomematicipGenericEntity, BinarySensorEntity): class HomematicipWaterDetector(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP water detector.""" - @property - def device_class(self) -> BinarySensorDeviceClass: - """Return the class of this sensor.""" - return BinarySensorDeviceClass.MOISTURE + _attr_device_class = BinarySensorDeviceClass.MOISTURE @property def is_on(self) -> bool: @@ -373,15 +352,12 @@ class HomematicipStormSensor(HomematicipGenericEntity, BinarySensorEntity): class HomematicipRainSensor(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP rain sensor.""" + _attr_device_class = BinarySensorDeviceClass.MOISTURE + def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize rain sensor.""" super().__init__(hap, device, "Raining") - @property - def device_class(self) -> BinarySensorDeviceClass: - """Return the class of this sensor.""" - return BinarySensorDeviceClass.MOISTURE - @property def is_on(self) -> bool: """Return true, if it is raining.""" @@ -391,15 +367,12 @@ class HomematicipRainSensor(HomematicipGenericEntity, BinarySensorEntity): class HomematicipSunshineSensor(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP sunshine sensor.""" + _attr_device_class = BinarySensorDeviceClass.LIGHT + def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize sunshine sensor.""" super().__init__(hap, device, post="Sunshine") - @property - def device_class(self) -> BinarySensorDeviceClass: - """Return the class of this sensor.""" - return BinarySensorDeviceClass.LIGHT - @property def is_on(self) -> bool: """Return true if sun is shining.""" @@ -420,15 +393,12 @@ class HomematicipSunshineSensor(HomematicipGenericEntity, BinarySensorEntity): class HomematicipBatterySensor(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP low battery sensor.""" + _attr_device_class = BinarySensorDeviceClass.BATTERY + def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize battery sensor.""" super().__init__(hap, device, post="Battery") - @property - def device_class(self) -> BinarySensorDeviceClass: - """Return the class of this sensor.""" - return BinarySensorDeviceClass.BATTERY - @property def is_on(self) -> bool: """Return true if battery is low.""" @@ -440,15 +410,12 @@ class HomematicipPluggableMainsFailureSurveillanceSensor( ): """Representation of the HomematicIP pluggable mains failure surveillance sensor.""" + _attr_device_class = BinarySensorDeviceClass.POWER + def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize pluggable mains failure surveillance sensor.""" super().__init__(hap, device) - @property - def device_class(self) -> BinarySensorDeviceClass: - """Return the class of this sensor.""" - return BinarySensorDeviceClass.POWER - @property def is_on(self) -> bool: """Return true if power mains fails.""" @@ -458,16 +425,13 @@ class HomematicipPluggableMainsFailureSurveillanceSensor( class HomematicipSecurityZoneSensorGroup(HomematicipGenericEntity, BinarySensorEntity): """Representation of the HomematicIP security zone sensor group.""" + _attr_device_class = BinarySensorDeviceClass.SAFETY + def __init__(self, hap: HomematicipHAP, device, post: str = "SecurityZone") -> None: """Initialize security zone group.""" device.modelType = f"HmIP-{post}" super().__init__(hap, device, post=post) - @property - def device_class(self) -> BinarySensorDeviceClass: - """Return the class of this sensor.""" - return BinarySensorDeviceClass.SAFETY - @property def available(self) -> bool: """Security-Group available.""" diff --git a/homeassistant/components/homematicip_cloud/cover.py b/homeassistant/components/homematicip_cloud/cover.py index e5007b5a15f..f5a9919579c 100644 --- a/homeassistant/components/homematicip_cloud/cover.py +++ b/homeassistant/components/homematicip_cloud/cover.py @@ -68,10 +68,7 @@ async def async_setup_entry( class HomematicipBlindModule(HomematicipGenericEntity, CoverEntity): """Representation of the HomematicIP blind module.""" - @property - def device_class(self) -> CoverDeviceClass: - """Return the class of the cover.""" - return CoverDeviceClass.BLIND + _attr_device_class = CoverDeviceClass.BLIND @property def current_cover_position(self) -> int | None: @@ -149,6 +146,8 @@ class HomematicipBlindModule(HomematicipGenericEntity, CoverEntity): class HomematicipMultiCoverShutter(HomematicipGenericEntity, CoverEntity): """Representation of the HomematicIP cover shutter.""" + _attr_device_class = CoverDeviceClass.SHUTTER + def __init__( self, hap: HomematicipHAP, @@ -161,11 +160,6 @@ class HomematicipMultiCoverShutter(HomematicipGenericEntity, CoverEntity): 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 def current_cover_position(self) -> int | None: """Return current position of cover.""" @@ -272,6 +266,8 @@ class HomematicipCoverSlats(HomematicipMultiCoverSlats, CoverEntity): class HomematicipGarageDoorModule(HomematicipGenericEntity, CoverEntity): """Representation of the HomematicIP Garage Door Module.""" + _attr_device_class = CoverDeviceClass.GARAGE + @property def current_cover_position(self) -> int | None: """Return current position of cover.""" @@ -283,11 +279,6 @@ class HomematicipGarageDoorModule(HomematicipGenericEntity, CoverEntity): } 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 def is_closed(self) -> bool | None: """Return if the cover is closed.""" @@ -309,16 +300,13 @@ class HomematicipGarageDoorModule(HomematicipGenericEntity, CoverEntity): class HomematicipCoverShutterGroup(HomematicipGenericEntity, CoverEntity): """Representation of the HomematicIP cover shutter group.""" + _attr_device_class = CoverDeviceClass.SHUTTER + def __init__(self, hap: HomematicipHAP, device, post: str = "ShutterGroup") -> None: """Initialize switching group.""" device.modelType = f"HmIP-{post}" 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 def current_cover_position(self) -> int | None: """Return current position of cover.""" diff --git a/homeassistant/components/homematicip_cloud/weather.py b/homeassistant/components/homematicip_cloud/weather.py index e913e1125f1..573f291d557 100644 --- a/homeassistant/components/homematicip_cloud/weather.py +++ b/homeassistant/components/homematicip_cloud/weather.py @@ -72,6 +72,7 @@ class HomematicipWeatherSensor(HomematicipGenericEntity, WeatherEntity): _attr_native_temperature_unit = UnitOfTemperature.CELSIUS _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR + _attr_attribution = "Powered by Homematic IP" def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize the weather sensor.""" @@ -97,11 +98,6 @@ class HomematicipWeatherSensor(HomematicipGenericEntity, WeatherEntity): """Return the wind speed.""" return self._device.windSpeed - @property - def attribution(self) -> str: - """Return the attribution.""" - return "Powered by Homematic IP" - @property def condition(self) -> str: """Return the current condition.""" @@ -128,6 +124,7 @@ class HomematicipHomeWeather(HomematicipGenericEntity, WeatherEntity): _attr_native_temperature_unit = UnitOfTemperature.CELSIUS _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR + _attr_attribution = "Powered by Homematic IP" def __init__(self, hap: HomematicipHAP) -> None: """Initialize the home weather.""" @@ -164,11 +161,6 @@ class HomematicipHomeWeather(HomematicipGenericEntity, WeatherEntity): """Return the wind bearing.""" return self._device.weather.windDirection - @property - def attribution(self) -> str: - """Return the attribution.""" - return "Powered by Homematic IP" - @property def condition(self) -> str | None: """Return the current condition."""