Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code maintenance for HomematicIP Cloud #28980

Merged
merged 2 commits into from Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 11 additions & 9 deletions homeassistant/components/homematicip_cloud/__init__.py
@@ -1,8 +1,10 @@
"""Support for HomematicIP Cloud devices."""
import logging
from pathlib import Path
from typing import Optional

from homematicip.aio.group import AsyncHeatingGroup
from homematicip.aio.home import AsyncHome
from homematicip.base.helpers import handle_config
import voluptuous as vol

Expand Down Expand Up @@ -135,7 +137,7 @@ async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
)
)

async def _async_activate_eco_mode_with_duration(service):
async def _async_activate_eco_mode_with_duration(service) -> None:
"""Service to activate eco mode with duration."""
duration = service.data[ATTR_DURATION]
hapid = service.data.get(ATTR_ACCESSPOINT_ID)
Expand All @@ -155,7 +157,7 @@ async def _async_activate_eco_mode_with_duration(service):
schema=SCHEMA_ACTIVATE_ECO_MODE_WITH_DURATION,
)

async def _async_activate_eco_mode_with_period(service):
async def _async_activate_eco_mode_with_period(service) -> None:
"""Service to activate eco mode with period."""
endtime = service.data[ATTR_ENDTIME]
hapid = service.data.get(ATTR_ACCESSPOINT_ID)
Expand All @@ -175,7 +177,7 @@ async def _async_activate_eco_mode_with_period(service):
schema=SCHEMA_ACTIVATE_ECO_MODE_WITH_PERIOD,
)

async def _async_activate_vacation(service):
async def _async_activate_vacation(service) -> None:
"""Service to activate vacation."""
endtime = service.data[ATTR_ENDTIME]
temperature = service.data[ATTR_TEMPERATURE]
Expand All @@ -196,7 +198,7 @@ async def _async_activate_vacation(service):
schema=SCHEMA_ACTIVATE_VACATION,
)

async def _async_deactivate_eco_mode(service):
async def _async_deactivate_eco_mode(service) -> None:
"""Service to deactivate eco mode."""
hapid = service.data.get(ATTR_ACCESSPOINT_ID)

Expand All @@ -215,7 +217,7 @@ async def _async_deactivate_eco_mode(service):
schema=SCHEMA_DEACTIVATE_ECO_MODE,
)

async def _async_deactivate_vacation(service):
async def _async_deactivate_vacation(service) -> None:
"""Service to deactivate vacation."""
hapid = service.data.get(ATTR_ACCESSPOINT_ID)

Expand All @@ -234,7 +236,7 @@ async def _async_deactivate_vacation(service):
schema=SCHEMA_DEACTIVATE_VACATION,
)

async def _set_active_climate_profile(service):
async def _set_active_climate_profile(service) -> None:
"""Service to set the active climate profile."""
entity_id_list = service.data[ATTR_ENTITY_ID]
climate_profile_index = service.data[ATTR_CLIMATE_PROFILE_INDEX] - 1
Expand All @@ -257,7 +259,7 @@ async def _set_active_climate_profile(service):
schema=SCHEMA_SET_ACTIVE_CLIMATE_PROFILE,
)

async def _async_dump_hap_config(service):
async def _async_dump_hap_config(service) -> None:
"""Service to dump the configuration of a Homematic IP Access Point."""
config_path = (
service.data.get(ATTR_CONFIG_OUTPUT_PATH) or hass.config.config_dir
Expand Down Expand Up @@ -287,7 +289,7 @@ async def _async_dump_hap_config(service):
schema=SCHEMA_DUMP_HAP_CONFIG,
)

def _get_home(hapid: str):
def _get_home(hapid: str) -> Optional[AsyncHome]:
"""Return a HmIP home."""
hap = hass.data[DOMAIN].get(hapid)
if hap:
Expand Down Expand Up @@ -324,7 +326,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
return True


async def async_unload_entry(hass, entry):
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
hap = hass.data[DOMAIN].pop(entry.data[HMIPC_HAPID])
return await hap.async_reset()
20 changes: 12 additions & 8 deletions homeassistant/components/homematicip_cloud/alarm_control_panel.py
@@ -1,5 +1,6 @@
"""Support for HomematicIP Cloud alarm control panel."""
import logging
from typing import Any, Dict

from homematicip.functionalHomes import SecurityAndAlarmHome

Expand All @@ -21,7 +22,9 @@
CONST_ALARM_CONTROL_PANEL_NAME = "HmIP Alarm Control Panel"


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
async def async_setup_platform(
hass, config, async_add_entities, discovery_info=None
) -> None:
"""Set up the HomematicIP Cloud alarm control devices."""
pass

Expand All @@ -40,9 +43,10 @@ class HomematicipAlarmControlPanel(AlarmControlPanel):
def __init__(self, hap: HomematicipHAP) -> None:
"""Initialize the alarm control panel."""
self._home = hap.home
_LOGGER.info("Setting up %s", self.name)

@property
def device_info(self):
def device_info(self) -> Dict[str, Any]:
"""Return device specific attributes."""
return {
"identifiers": {(HMIPC_DOMAIN, f"ACP {self._home.id}")},
Expand Down Expand Up @@ -70,26 +74,26 @@ def state(self) -> str:
return STATE_ALARM_DISARMED

@property
def _security_and_alarm(self):
def _security_and_alarm(self) -> SecurityAndAlarmHome:
return self._home.get_functionalHome(SecurityAndAlarmHome)

async def async_alarm_disarm(self, code=None):
async def async_alarm_disarm(self, code=None) -> None:
"""Send disarm command."""
await self._home.set_security_zones_activation(False, False)

async def async_alarm_arm_home(self, code=None):
async def async_alarm_arm_home(self, code=None) -> None:
"""Send arm home command."""
await self._home.set_security_zones_activation(False, True)

async def async_alarm_arm_away(self, code=None):
async def async_alarm_arm_away(self, code=None) -> None:
"""Send arm away command."""
await self._home.set_security_zones_activation(True, True)

async def async_added_to_hass(self):
async def async_added_to_hass(self) -> None:
"""Register callbacks."""
self._home.on_update(self._async_device_changed)

def _async_device_changed(self, *args, **kwargs):
def _async_device_changed(self, *args, **kwargs) -> None:
"""Handle device state changes."""
_LOGGER.debug("Event %s (%s)", self.name, CONST_ALARM_CONTROL_PANEL_NAME)
self.async_schedule_update_ha_state()
Expand Down
45 changes: 24 additions & 21 deletions homeassistant/components/homematicip_cloud/binary_sensor.py
@@ -1,5 +1,6 @@
"""Support for HomematicIP Cloud binary sensor."""
import logging
from typing import Any, Dict

from homematicip.aio.device import (
AsyncAccelerationSensor,
Expand Down Expand Up @@ -72,7 +73,9 @@
}


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
async def async_setup_platform(
hass, config, async_add_entities, discovery_info=None
) -> None:
"""Set up the HomematicIP Cloud binary sensor devices."""
pass

Expand All @@ -82,17 +85,17 @@ async def async_setup_entry(
) -> None:
"""Set up the HomematicIP Cloud binary sensor from a config entry."""
hap = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]]
devices = []
entities = []
for device in hap.home.devices:
if isinstance(device, AsyncAccelerationSensor):
devices.append(HomematicipAccelerationSensor(hap, device))
entities.append(HomematicipAccelerationSensor(hap, device))
if isinstance(device, (AsyncContactInterface, AsyncFullFlushContactInterface)):
devices.append(HomematicipContactInterface(hap, device))
entities.append(HomematicipContactInterface(hap, device))
if isinstance(
device,
(AsyncShutterContact, AsyncShutterContactMagnetic, AsyncRotaryHandleSensor),
):
devices.append(HomematicipShutterContact(hap, device))
entities.append(HomematicipShutterContact(hap, device))
if isinstance(
device,
(
Expand All @@ -101,31 +104,31 @@ async def async_setup_entry(
AsyncMotionDetectorPushButton,
),
):
devices.append(HomematicipMotionDetector(hap, device))
entities.append(HomematicipMotionDetector(hap, device))
if isinstance(device, AsyncPresenceDetectorIndoor):
devices.append(HomematicipPresenceDetector(hap, device))
entities.append(HomematicipPresenceDetector(hap, device))
if isinstance(device, AsyncSmokeDetector):
devices.append(HomematicipSmokeDetector(hap, device))
entities.append(HomematicipSmokeDetector(hap, device))
if isinstance(device, AsyncWaterSensor):
devices.append(HomematicipWaterDetector(hap, device))
entities.append(HomematicipWaterDetector(hap, device))
if isinstance(device, (AsyncWeatherSensorPlus, AsyncWeatherSensorPro)):
devices.append(HomematicipRainSensor(hap, device))
entities.append(HomematicipRainSensor(hap, device))
if isinstance(
device, (AsyncWeatherSensor, AsyncWeatherSensorPlus, AsyncWeatherSensorPro)
):
devices.append(HomematicipStormSensor(hap, device))
devices.append(HomematicipSunshineSensor(hap, device))
entities.append(HomematicipStormSensor(hap, device))
entities.append(HomematicipSunshineSensor(hap, device))
if isinstance(device, AsyncDevice) and device.lowBat is not None:
devices.append(HomematicipBatterySensor(hap, device))
entities.append(HomematicipBatterySensor(hap, device))

for group in hap.home.groups:
if isinstance(group, AsyncSecurityGroup):
devices.append(HomematicipSecuritySensorGroup(hap, group))
entities.append(HomematicipSecuritySensorGroup(hap, group))
elif isinstance(group, AsyncSecurityZoneGroup):
devices.append(HomematicipSecurityZoneSensorGroup(hap, group))
entities.append(HomematicipSecurityZoneSensorGroup(hap, group))

if devices:
async_add_entities(devices)
if entities:
async_add_entities(entities)


class HomematicipAccelerationSensor(HomematicipGenericDevice, BinarySensorDevice):
Expand All @@ -142,7 +145,7 @@ def is_on(self) -> bool:
return self._device.accelerationSensorTriggered

@property
def device_state_attributes(self):
def device_state_attributes(self) -> Dict[str, Any]:
"""Return the state attributes of the acceleration sensor."""
state_attr = super().device_state_attributes

Expand Down Expand Up @@ -296,7 +299,7 @@ def is_on(self) -> bool:
return self._device.sunshine

@property
def device_state_attributes(self):
def device_state_attributes(self) -> Dict[str, Any]:
"""Return the state attributes of the illuminance sensor."""
state_attr = super().device_state_attributes

Expand Down Expand Up @@ -346,7 +349,7 @@ def available(self) -> bool:
return True

@property
def device_state_attributes(self):
def device_state_attributes(self) -> Dict[str, Any]:
"""Return the state attributes of the security zone group."""
state_attr = super().device_state_attributes

Expand Down Expand Up @@ -390,7 +393,7 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
super().__init__(hap, device, "Sensors")

@property
def device_state_attributes(self):
def device_state_attributes(self) -> Dict[str, Any]:
"""Return the state attributes of the security group."""
state_attr = super().device_state_attributes

Expand Down