def setup(hass, config): """Set up the HomematicIP component.""" # pylint: disable=import-error, no-name-in-module from homematicip.home import Home hass.data.setdefault(DOMAIN, {}) homes = hass.data[DOMAIN] accesspoints = config.get(DOMAIN, []) def _update_event(events): """Handle incoming HomeMaticIP events.""" for event in events: etype = event['eventType'] edata = event['data'] if etype == 'DEVICE_CHANGED': dispatcher_send(hass, EVENT_DEVICE_CHANGED, edata.id) elif etype == 'GROUP_CHANGED': dispatcher_send(hass, EVENT_GROUP_CHANGED, edata.id) elif etype == 'HOME_CHANGED': dispatcher_send(hass, EVENT_HOME_CHANGED, edata.id) elif etype == 'JOURNAL_CHANGED': dispatcher_send(hass, EVENT_SECURITY_CHANGED, edata.id) return True for device in accesspoints: name = device.get(CONF_NAME) accesspoint = device.get(CONF_ACCESSPOINT) authtoken = device.get(CONF_AUTHTOKEN) home = Home() if name.lower() == 'none': name = '' home.label = name try: home.set_auth_token(authtoken) home.init(accesspoint) if home.get_current_state(): _LOGGER.info("Connection to HMIP established") else: _LOGGER.warning("Connection to HMIP could not be established") return False except timeout: _LOGGER.warning("Connection to HMIP could not be established") return False homes[home.id] = home home.onEvent += _update_event home.enable_events() _LOGGER.info('HUB name: %s, id: %s', home.label, home.id) for component in ['sensor']: load_platform(hass, component, DOMAIN, {'homeid': home.id}, config) return True
def test_security_setZoneActivationDelay(fake_home: Home): with no_ssl_verification(): securityAlarmHome = fake_home.get_functionalHome(SecurityAndAlarmHome) assert securityAlarmHome.zoneActivationDelay == 0.0 fake_home.set_zone_activation_delay(5.0) fake_home.get_current_state() securityAlarmHome = fake_home.get_functionalHome(SecurityAndAlarmHome) assert securityAlarmHome.zoneActivationDelay == 5.0 fake_home.set_zone_activation_delay(0.0) fake_home.get_current_state() securityAlarmHome = fake_home.get_functionalHome(SecurityAndAlarmHome) assert securityAlarmHome.zoneActivationDelay == 0.0
def test_indoor_climate_home(fake_home: Home): with no_ssl_verification(): for fh in fake_home.functionalHomes: if not isinstance(fh, IndoorClimateHome): continue assert fh.active is True assert fh.absenceType == AbsenceType.NOT_ABSENT assert fh.coolingEnabled is False assert fh.ecoDuration == EcoDuration.PERMANENT assert fh.ecoTemperature == 17.0 assert fh.optimumStartStopEnabled is False minutes = 20 fake_home.activate_absence_with_duration(minutes) absence_end = datetime.now() + timedelta(minutes=minutes) absence_end = absence_end.replace(second=0, microsecond=0) fake_home.get_current_state() assert fh.absenceType == AbsenceType.PERIOD assert fh.absenceEndTime == absence_end absence_end = datetime.strptime("2100_01_01 22:22", "%Y_%m_%d %H:%M") fake_home.activate_absence_with_period(absence_end) fake_home.get_current_state() assert fh.absenceType == AbsenceType.PERIOD assert fh.absenceEndTime == absence_end fake_home.deactivate_absence() fake_home.get_current_state() assert fh.absenceType == AbsenceType.NOT_ABSENT assert fh.absenceEndTime is None
def test_security_setIntrusionAlertThroughSmokeDetectors(fake_home: Home): with no_ssl_verification(): securityAlarmHome = fake_home.get_functionalHome(SecurityAndAlarmHome) assert securityAlarmHome.intrusionAlertThroughSmokeDetectors is False fake_home.set_intrusion_alert_through_smoke_detectors(True) fake_home.get_current_state() securityAlarmHome = fake_home.get_functionalHome(SecurityAndAlarmHome) assert securityAlarmHome.intrusionAlertThroughSmokeDetectors is True fake_home.set_intrusion_alert_through_smoke_detectors(False) fake_home.get_current_state() securityAlarmHome = fake_home.get_functionalHome(SecurityAndAlarmHome) assert securityAlarmHome.intrusionAlertThroughSmokeDetectors is False
def test_basic_device_functions(fake_home: Home): with no_ssl_verification(): d = fake_home.search_device_by_id('3014F7110000000000000009') assert d.label == "Brunnen" assert d.routerModuleEnabled == True d.set_label("new label") d.set_router_module_enabled(False) fake_home.get_current_state() d = fake_home.search_device_by_id('3014F7110000000000000009') assert d.label == "new label" assert d.routerModuleEnabled == False d.set_label("other label") d.set_router_module_enabled(True) fake_home.get_current_state() d = fake_home.search_device_by_id('3014F7110000000000000009') assert d.label == "other label" assert d.routerModuleEnabled == True d2 = fake_home.search_device_by_id('3014F7110000000000000005') d.delete() fake_home.get_current_state() dNotFound = fake_home.search_device_by_id('3014F7110000000000000009') assert dNotFound == None assert d2 is fake_home.search_device_by_id( '3014F7110000000000000005' ) # make sure that the objects got updated and not completely renewed #check if the server is answering properly result = d.set_label("BLa") assert result["errorCode"] == "INVALID_DEVICE" result = d.delete() assert result["errorCode"] == "INVALID_DEVICE"