Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 38 additions & 48 deletions homeassistant/components/homematicip_cloud/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,25 @@
_LOGGER = logging.getLogger(__name__)

ATTR_LOW_BATTERY = "low_battery"
ATTR_MOISTUREDETECTED = "moisture detected"
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
ATTR_MOTIONDETECTED = "motion detected"
ATTR_PRESENCEDETECTED = "presence detected"
ATTR_POWERMAINSFAILURE = "power mains failure"
ATTR_WINDOWSTATE = "window state"
ATTR_MOISTUREDETECTED = "moisture detected"
ATTR_WATERLEVELDETECTED = "water level detected"
ATTR_PRESENCEDETECTED = "presence detected"
ATTR_SMOKEDETECTORALARM = "smoke detector alarm"
ATTR_TODAY_SUNSHINE_DURATION = "today_sunshine_duration_in_minutes"
ATTR_WATERLEVELDETECTED = "water level detected"
ATTR_WINDOWSTATE = "window state"

GROUP_ATTRIBUTES = {
"lowBat": ATTR_LOW_BATTERY,
"modelType": ATTR_MODEL_TYPE,
"moistureDetected": ATTR_MOISTUREDETECTED,
"motionDetected": ATTR_MOTIONDETECTED,
"powerMainsFailure": ATTR_POWERMAINSFAILURE,
"presenceDetected": ATTR_PRESENCEDETECTED,
"unreach": ATTR_GROUP_MEMBER_UNREACHABLE,
"waterlevelDetected": ATTR_WATERLEVELDETECTED,
}


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
Expand Down Expand Up @@ -118,8 +129,6 @@ def device_class(self) -> str:
@property
def is_on(self) -> bool:
"""Return true if the contact interface is on/open."""
if hasattr(self._device, "sabotage") and self._device.sabotage:
return True
if self._device.windowState is None:
return None
return self._device.windowState != WindowState.CLOSED
Expand All @@ -136,8 +145,6 @@ def device_class(self) -> str:
@property
def is_on(self) -> bool:
"""Return true if the shutter contact is on/open."""
if hasattr(self._device, "sabotage") and self._device.sabotage:
return True
if self._device.windowState is None:
return None
return self._device.windowState != WindowState.CLOSED
Expand All @@ -154,8 +161,6 @@ def device_class(self) -> str:
@property
def is_on(self) -> bool:
"""Return true if motion is detected."""
if hasattr(self._device, "sabotage") and self._device.sabotage:
return True
return self._device.motionDetected


Expand All @@ -170,8 +175,6 @@ def device_class(self) -> str:
@property
def is_on(self) -> bool:
"""Return true if presence is detected."""
if hasattr(self._device, "sabotage") and self._device.sabotage:
return True
return self._device.presenceDetected


Expand Down Expand Up @@ -259,13 +262,13 @@ def is_on(self) -> bool:
@property
def device_state_attributes(self):
"""Return the state attributes of the illuminance sensor."""
attr = super().device_state_attributes
if (
hasattr(self._device, "todaySunshineDuration")
and self._device.todaySunshineDuration
):
attr[ATTR_TODAY_SUNSHINE_DURATION] = self._device.todaySunshineDuration
return attr
state_attr = super().device_state_attributes

today_sunshine_duration = getattr(self._device, "todaySunshineDuration", None)
if today_sunshine_duration:
state_attr[ATTR_TODAY_SUNSHINE_DURATION] = today_sunshine_duration

return state_attr


class HomematicipBatterySensor(HomematicipGenericDevice, BinarySensorDevice):
Expand Down Expand Up @@ -309,21 +312,18 @@ def available(self) -> bool:
@property
def device_state_attributes(self):
"""Return the state attributes of the security zone group."""
attr = {ATTR_MODEL_TYPE: self._device.modelType}
state_attr = {ATTR_MODEL_TYPE: self._device.modelType}

if self._device.motionDetected:
attr[ATTR_MOTIONDETECTED] = True
if self._device.presenceDetected:
attr[ATTR_PRESENCEDETECTED] = True
for attr, attr_key in GROUP_ATTRIBUTES.items():
attr_value = getattr(self._device, attr, None)
if attr_value:
state_attr[attr_key] = attr_value

if (
self._device.windowState is not None
and self._device.windowState != WindowState.CLOSED
):
attr[ATTR_WINDOWSTATE] = str(self._device.windowState)
if self._device.unreach:
attr[ATTR_GROUP_MEMBER_UNREACHABLE] = True
return attr
window_state = getattr(self._device, "windowState", None)
if window_state and window_state != WindowState.CLOSED:
state_attr[ATTR_WINDOWSTATE] = str(window_state)

return state_attr

@property
def is_on(self) -> bool:
Expand Down Expand Up @@ -356,23 +356,13 @@ def __init__(self, home: AsyncHome, device) -> None:
@property
def device_state_attributes(self):
"""Return the state attributes of the security group."""
attr = super().device_state_attributes

if self._device.powerMainsFailure:
attr[ATTR_POWERMAINSFAILURE] = True
if self._device.moistureDetected:
attr[ATTR_MOISTUREDETECTED] = True
if self._device.waterlevelDetected:
attr[ATTR_WATERLEVELDETECTED] = True
if self._device.lowBat:
attr[ATTR_LOW_BATTERY] = True
if (
self._device.smokeDetectorAlarmType is not None
and self._device.smokeDetectorAlarmType != SmokeDetectorAlarmType.IDLE_OFF
):
attr[ATTR_SMOKEDETECTORALARM] = str(self._device.smokeDetectorAlarmType)
state_attr = super().device_state_attributes

smoke_detector_at = getattr(self._device, "smokeDetectorAlarmType", None)
if smoke_detector_at and smoke_detector_at != SmokeDetectorAlarmType.IDLE_OFF:
state_attr[ATTR_SMOKEDETECTORALARM] = str(smoke_detector_at)

return attr
return state_attr

@property
def is_on(self) -> bool:
Expand Down
26 changes: 15 additions & 11 deletions homeassistant/components/homematicip_cloud/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ class HomematicipLightMeasuring(HomematicipLight):
@property
def device_state_attributes(self):
"""Return the state attributes of the generic device."""
attr = super().device_state_attributes
if self._device.currentPowerConsumption > 0.05:
attr[ATTR_POWER_CONSUMPTION] = round(
self._device.currentPowerConsumption, 2
)
attr[ATTR_ENERGY_COUNTER] = round(self._device.energyCounter, 2)
return attr
state_attr = super().device_state_attributes

current_power_consumption = self._device.currentPowerConsumption
if current_power_consumption > 0.05:
state_attr[ATTR_POWER_CONSUMPTION] = round(current_power_consumption, 2)

state_attr[ATTR_ENERGY_COUNTER] = round(self._device.energyCounter, 2)

return state_attr


class HomematicipDimmer(HomematicipGenericDevice, Light):
Expand Down Expand Up @@ -187,15 +189,17 @@ def hs_color(self) -> tuple:
@property
def device_state_attributes(self):
"""Return the state attributes of the generic device."""
attr = super().device_state_attributes
state_attr = super().device_state_attributes

if self.is_on:
attr[ATTR_COLOR_NAME] = self._func_channel.simpleRGBColorState
return attr
state_attr[ATTR_COLOR_NAME] = self._func_channel.simpleRGBColorState

return state_attr

@property
def name(self) -> str:
"""Return the name of the generic device."""
return "{} {}".format(super().name, "Notification")
return f"{super().name} Notification"

@property
def supported_features(self) -> int:
Expand Down
34 changes: 18 additions & 16 deletions homeassistant/components/homematicip_cloud/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@ def unit_of_measurement(self) -> str:
@property
def device_state_attributes(self):
"""Return the state attributes of the windspeed sensor."""
attr = super().device_state_attributes
if (
hasattr(self._device, "temperatureOffset")
and self._device.temperatureOffset
):
attr[ATTR_TEMPERATURE_OFFSET] = self._device.temperatureOffset
return attr
state_attr = super().device_state_attributes

temperature_offset = getattr(self._device, "temperatureOffset", None)
if temperature_offset:
state_attr[ATTR_TEMPERATURE_OFFSET] = temperature_offset

return state_attr


class HomematicipIlluminanceSensor(HomematicipGenericDevice):
Expand Down Expand Up @@ -307,15 +307,17 @@ def unit_of_measurement(self) -> str:
@property
def device_state_attributes(self):
"""Return the state attributes of the wind speed sensor."""
attr = super().device_state_attributes
if hasattr(self._device, "windDirection") and self._device.windDirection:
attr[ATTR_WIND_DIRECTION] = _get_wind_direction(self._device.windDirection)
if (
hasattr(self._device, "windDirectionVariation")
and self._device.windDirectionVariation
):
attr[ATTR_WIND_DIRECTION_VARIATION] = self._device.windDirectionVariation
return attr
state_attr = super().device_state_attributes

wind_direction = getattr(self._device, "windDirection", None)
if wind_direction:
state_attr[ATTR_WIND_DIRECTION] = _get_wind_direction(wind_direction)

wind_direction_variation = getattr(self._device, "windDirectionVariation", None)
if wind_direction_variation:
state_attr[ATTR_WIND_DIRECTION_VARIATION] = wind_direction_variation

return state_attr


class HomematicipTodayRainSensor(HomematicipGenericDevice):
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/homematicip_cloud/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ def available(self) -> bool:
@property
def device_state_attributes(self):
"""Return the state attributes of the switch-group."""
attr = {}
state_attr = {}
if self._device.unreach:
attr[ATTR_GROUP_MEMBER_UNREACHABLE] = True
return attr
state_attr[ATTR_GROUP_MEMBER_UNREACHABLE] = True
return state_attr

async def async_turn_on(self, **kwargs):
"""Turn the group on."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/homematicip_cloud/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def attribution(self) -> str:
@property
def condition(self) -> str:
"""Return the current condition."""
if hasattr(self._device, "raining") and self._device.raining:
if getattr(self._device, "raining", None):
return "rainy"
if self._device.storm:
return "windy"
Expand Down