-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
- Loading branch information
Showing
14 changed files
with
670 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...java/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlAlarmConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) 2010-2022 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.nikohomecontrol.internal.handler; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
|
||
/** | ||
* {@link NikoHomeControlAlarmConfig} is the general config class for Niko Home Control Alarm systems. | ||
* | ||
* @author Mark Herwege - Initial Contribution | ||
*/ | ||
@NonNullByDefault | ||
public class NikoHomeControlAlarmConfig { | ||
public String alarmId = ""; | ||
} |
191 changes: 191 additions & 0 deletions
191
...ava/org/openhab/binding/nikohomecontrol/internal/handler/NikoHomeControlAlarmHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/** | ||
* Copyright (c) 2010-2022 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.nikohomecontrol.internal.handler; | ||
|
||
import static org.openhab.binding.nikohomecontrol.internal.NikoHomeControlBindingConstants.*; | ||
import static org.openhab.binding.nikohomecontrol.internal.protocol.NikoHomeControlConstants.*; | ||
import static org.openhab.core.types.RefreshType.REFRESH; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.binding.nikohomecontrol.internal.protocol.NhcAlarm; | ||
import org.openhab.binding.nikohomecontrol.internal.protocol.NhcAlarmEvent; | ||
import org.openhab.binding.nikohomecontrol.internal.protocol.NikoHomeControlCommunication; | ||
import org.openhab.binding.nikohomecontrol.internal.protocol.nhc2.NhcAlarm2; | ||
import org.openhab.core.library.types.OnOffType; | ||
import org.openhab.core.library.types.StringType; | ||
import org.openhab.core.thing.Bridge; | ||
import org.openhab.core.thing.ChannelUID; | ||
import org.openhab.core.thing.Thing; | ||
import org.openhab.core.thing.ThingStatus; | ||
import org.openhab.core.thing.ThingStatusDetail; | ||
import org.openhab.core.types.Command; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The {@link NikoHomeControlAlarmHandler} is responsible for handling commands, which are | ||
* sent to one of the channels. | ||
* | ||
* @author Mark Herwege - Initial Contribution | ||
*/ | ||
@NonNullByDefault | ||
public class NikoHomeControlAlarmHandler extends NikoHomeControlBaseHandler implements NhcAlarmEvent { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(NikoHomeControlAlarmHandler.class); | ||
|
||
private volatile @Nullable NhcAlarm nhcAlarm; | ||
|
||
public NikoHomeControlAlarmHandler(Thing thing) { | ||
super(thing); | ||
} | ||
|
||
@Override | ||
void handleCommandSelection(ChannelUID channelUID, Command command) { | ||
NhcAlarm nhcAlarm = this.nhcAlarm; | ||
if (nhcAlarm == null) { | ||
logger.debug("alarm device with ID {} not initialized", deviceId); | ||
return; | ||
} | ||
|
||
logger.debug("handle command {} for {}", command, channelUID); | ||
|
||
if (REFRESH.equals(command)) { | ||
|
||
} else if (CHANNEL_SWITCH.equals(channelUID.getId()) && command instanceof OnOffType) { | ||
OnOffType s = (OnOffType) command; | ||
if (OnOffType.ON.equals(s)) { | ||
nhcAlarm.executeArm(); | ||
} else { | ||
nhcAlarm.executeDisarm(); | ||
} | ||
} else { | ||
logger.debug("unexpected command for channel {}", channelUID.getId()); | ||
} | ||
|
||
updateStatus(ThingStatus.ONLINE); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
initialized = false; | ||
|
||
NikoHomeControlAlarmConfig config = getConfig().as(NikoHomeControlAlarmConfig.class); | ||
deviceId = config.alarmId; | ||
|
||
NikoHomeControlBridgeHandler bridgeHandler = getBridgeHandler(); | ||
if (bridgeHandler == null) { | ||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, | ||
"@text/offline.configuration-error.invalid-bridge-handler"); | ||
return; | ||
} | ||
|
||
updateStatus(ThingStatus.UNKNOWN); | ||
|
||
Bridge bridge = getBridge(); | ||
if ((bridge != null) && ThingStatus.ONLINE.equals(bridge.getStatus())) { | ||
// We need to do this in a separate thread because we may have to wait for the | ||
// communication to become active | ||
scheduler.submit(this::startCommunication); | ||
} | ||
} | ||
|
||
@Override | ||
synchronized void startCommunication() { | ||
NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler()); | ||
|
||
if (nhcComm == null) { | ||
return; | ||
} | ||
|
||
if (!nhcComm.communicationActive()) { | ||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, | ||
"@text/offline.communication-error"); | ||
return; | ||
} | ||
|
||
NhcAlarm nhcAlarm = nhcComm.getAlarmDevices().get(deviceId); | ||
if (nhcAlarm == null) { | ||
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, | ||
"@text/offline.configuration-error.deviceId"); | ||
return; | ||
} | ||
|
||
nhcAlarm.setEventHandler(this); | ||
|
||
updateProperties(nhcAlarm); | ||
|
||
String location = nhcAlarm.getLocation(); | ||
if (thing.getLocation() == null) { | ||
thing.setLocation(location); | ||
} | ||
|
||
this.nhcAlarm = nhcAlarm; | ||
|
||
initialized = true; | ||
deviceInitialized(); | ||
} | ||
|
||
@Override | ||
void refresh() { | ||
NhcAlarm alarm = nhcAlarm; | ||
if (alarm != null) { | ||
alarmEvent(alarm.getState()); | ||
} | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
NikoHomeControlCommunication nhcComm = getCommunication(getBridgeHandler()); | ||
if (nhcComm != null) { | ||
NhcAlarm alarm = nhcComm.getAlarmDevices().get(deviceId); | ||
if (alarm != null) { | ||
alarm.unsetEventHandler(); | ||
} | ||
} | ||
nhcAlarm = null; | ||
super.dispose(); | ||
} | ||
|
||
private void updateProperties(NhcAlarm nhcAlarm) { | ||
Map<String, String> properties = new HashMap<>(); | ||
|
||
if (nhcAlarm instanceof NhcAlarm2) { | ||
NhcAlarm2 alarm = (NhcAlarm2) nhcAlarm; | ||
properties.put(PROPERTY_DEVICE_TYPE, alarm.getDeviceType()); | ||
properties.put(PROPERTY_DEVICE_TECHNOLOGY, alarm.getDeviceTechnology()); | ||
properties.put(PROPERTY_DEVICE_MODEL, alarm.getDeviceModel()); | ||
} | ||
|
||
thing.setProperties(properties); | ||
} | ||
|
||
@Override | ||
public void alarmEvent(String state) { | ||
NhcAlarm nhcAlarm = this.nhcAlarm; | ||
if (nhcAlarm == null) { | ||
logger.debug(" alarm device with ID {} not initialized", deviceId); | ||
return; | ||
} | ||
|
||
updateState(CHANNEL_SWITCH, NHCOFF.equals(state) ? OnOffType.OFF : OnOffType.ON); | ||
updateState(CHANNEL_ALARM_STATE, StringType.valueOf(ALARMSTATES.get(state))); | ||
if (NHCTRIGGERED.equals(state)) { | ||
triggerChannel(CHANNEL_ALARM); | ||
} | ||
updateStatus(ThingStatus.ONLINE); | ||
} | ||
} |
Oops, something went wrong.