-
-
Notifications
You must be signed in to change notification settings - Fork 112
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
Add channel for Eurotronic Spirit ZigBee Window Open Mode #781
Open
rs22
wants to merge
1
commit into
openhab:main
Choose a base branch
from
rs22:eurotronic_spzb0001
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
195 changes: 195 additions & 0 deletions
195
...penhab/binding/zigbee/internal/converter/ZigBeeConverterEurotronicSpzb0001WindowOpen.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,195 @@ | ||
/** | ||
* 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.zigbee.internal.converter; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import org.openhab.binding.zigbee.ZigBeeBindingConstants; | ||
import org.openhab.binding.zigbee.converter.ZigBeeBaseChannelConverter; | ||
import org.openhab.binding.zigbee.handler.ZigBeeThingHandler; | ||
import org.openhab.core.library.types.OnOffType; | ||
import org.openhab.core.thing.Channel; | ||
import org.openhab.core.thing.ThingUID; | ||
import org.openhab.core.thing.binding.builder.ChannelBuilder; | ||
import org.openhab.core.types.Command; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.zsmartsystems.zigbee.CommandResult; | ||
import com.zsmartsystems.zigbee.ZigBeeEndpoint; | ||
import com.zsmartsystems.zigbee.zcl.ZclAttribute; | ||
import com.zsmartsystems.zigbee.zcl.ZclAttributeListener; | ||
import com.zsmartsystems.zigbee.zcl.clusters.ZclThermostatCluster; | ||
import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType; | ||
import com.zsmartsystems.zigbee.zcl.protocol.ZclDataType; | ||
|
||
/** | ||
* Converter for the thermostat system mode channel. The SystemMode attribute specifies the current operating mode of | ||
* the thermostat, | ||
* | ||
* @author Robert Schmid - Initial Contribution | ||
* | ||
*/ | ||
public class ZigBeeConverterEurotronicSpzb0001WindowOpen extends ZigBeeBaseChannelConverter | ||
implements ZclAttributeListener { | ||
private Logger logger = LoggerFactory.getLogger(ZigBeeConverterEurotronicSpzb0001WindowOpen.class); | ||
|
||
private final static int MANUFACTURER_EUROTRONIC = 0x1037; | ||
private final static int ATTR_HOST_FLAGS = 0x4008; | ||
private final static int WINDOW_OPEN_DISABLED = 16; | ||
private final static int WINDOW_OPEN_ENABLED = 32; | ||
|
||
private ZclThermostatCluster cluster; | ||
private ZclAttribute attribute; | ||
|
||
@Override | ||
public Set<Integer> getImplementedClientClusters() { | ||
return Collections.singleton(ZclThermostatCluster.CLUSTER_ID); | ||
} | ||
|
||
@Override | ||
public Set<Integer> getImplementedServerClusters() { | ||
return Collections.emptySet(); | ||
} | ||
|
||
private ZclThermostatCluster getCluster(ZigBeeEndpoint endpoint) { | ||
ZclThermostatCluster cluster = (ZclThermostatCluster) endpoint.getInputCluster(ZclThermostatCluster.CLUSTER_ID); | ||
if (cluster == null) { | ||
return null; | ||
} | ||
|
||
ZclAttribute hostFlagsAttribute = new ZclAttribute(cluster, ATTR_HOST_FLAGS, "Host Flags", | ||
ZclDataType.UNSIGNED_24_BIT_INTEGER, false, true, true, true, MANUFACTURER_EUROTRONIC); | ||
cluster.addAttributes(new HashSet<>(Arrays.asList(hostFlagsAttribute))); | ||
|
||
return cluster; | ||
} | ||
|
||
@Override | ||
public boolean initializeDevice() { | ||
ZclThermostatCluster serverCluster = getCluster(endpoint); | ||
if (serverCluster == null) { | ||
logger.error("{}: Error opening device thermostat cluster", endpoint.getIeeeAddress()); | ||
return false; | ||
} | ||
|
||
try { | ||
CommandResult bindResponse = bind(serverCluster).get(); | ||
if (bindResponse.isSuccess()) { | ||
// Configure reporting | ||
ZclAttribute attribute = serverCluster.getAttribute(ATTR_HOST_FLAGS); | ||
CommandResult reportingResponse = attribute | ||
.setReporting(REPORTING_PERIOD_DEFAULT_MIN, REPORTING_PERIOD_DEFAULT_MAX).get(); | ||
handleReportingResponse(reportingResponse, POLLING_PERIOD_DEFAULT, REPORTING_PERIOD_DEFAULT_MAX); | ||
} else { | ||
logger.debug("{}: Failed to bind thermostat cluster", endpoint.getIeeeAddress()); | ||
} | ||
} catch (InterruptedException | ExecutionException e) { | ||
logger.error("{}: Exception setting reporting ", endpoint.getIeeeAddress(), e); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public boolean initializeConverter(ZigBeeThingHandler thing) { | ||
super.initializeConverter(thing); | ||
cluster = getCluster(endpoint); | ||
if (cluster == null) { | ||
logger.error("{}: Error opening device thermostat cluster", endpoint.getIeeeAddress()); | ||
return false; | ||
} | ||
|
||
attribute = cluster.getAttribute(ATTR_HOST_FLAGS); | ||
if (attribute == null) { | ||
logger.error("{}: Error opening device thermostat Eurotronic host flags attribute", endpoint.getIeeeAddress()); | ||
return false; | ||
} | ||
|
||
// Add a listener, then request the status | ||
cluster.addAttributeListener(this); | ||
return true; | ||
} | ||
|
||
@Override | ||
public void disposeConverter() { | ||
cluster.removeAttributeListener(this); | ||
} | ||
|
||
@Override | ||
public void handleCommand(final Command command) { | ||
Integer value = null; | ||
if (command instanceof OnOffType) { | ||
// OnOff switches between OFF=WINDOW_OPEN_DISABLED and ON=WINDOW_OPEN_ENABLED | ||
value = command == OnOffType.ON ? WINDOW_OPEN_ENABLED : WINDOW_OPEN_DISABLED; | ||
} | ||
|
||
if (value == null) { | ||
logger.warn("{}: Host flags command {} [{}] was not processed", endpoint.getIeeeAddress(), command, | ||
command.getClass().getSimpleName()); | ||
return; | ||
} | ||
|
||
monitorCommandResponse(command, attribute.writeValue(value)); | ||
} | ||
|
||
@Override | ||
public void handleRefresh() { | ||
attribute.readValue(0); | ||
} | ||
|
||
@Override | ||
public Channel getChannel(ThingUID thingUID, ZigBeeEndpoint endpoint) { | ||
ZclThermostatCluster cluster = getCluster(endpoint); | ||
if (cluster == null) { | ||
logger.trace("{}: Thermostat cluster not found", endpoint.getIeeeAddress()); | ||
return null; | ||
} | ||
|
||
// Try to read the host flags attribute | ||
ZclAttribute attribute = cluster.getAttribute(ATTR_HOST_FLAGS); | ||
Object value = attribute.readValue(Long.MAX_VALUE); | ||
if (value == null) { | ||
logger.trace("{}: Thermostat host flags returned null", endpoint.getIeeeAddress()); | ||
return null; | ||
} | ||
|
||
return ChannelBuilder | ||
.create(createChannelUID(thingUID, endpoint, | ||
ZigBeeBindingConstants.CHANNEL_NAME_EUROTRONIC_SPZB001_WINDOW_OPEN), | ||
ZigBeeBindingConstants.ITEM_TYPE_SWITCH) | ||
.withType(ZigBeeBindingConstants.CHANNEL_EUROTRONIC_SPZB001_WINDOW_OPEN) | ||
.withLabel(ZigBeeBindingConstants.CHANNEL_LABEL_EUROTRONIC_SPZB001_WINDOW_OPEN) | ||
.withProperties(createProperties(endpoint)).build(); | ||
} | ||
|
||
@Override | ||
public void attributeUpdated(ZclAttribute attribute, Object val) { | ||
logger.debug("{}: ZigBee attribute reports {}", endpoint.getIeeeAddress(), attribute); | ||
if (attribute.getClusterType() == ZclClusterType.THERMOSTAT | ||
&& attribute.isManufacturerSpecific() | ||
&& attribute.getManufacturerCode() == MANUFACTURER_EUROTRONIC | ||
&& attribute.getId() == ATTR_HOST_FLAGS) { | ||
Integer value = (Integer) val; | ||
if (value != null && (value & WINDOW_OPEN_DISABLED) != 0) { | ||
updateChannelState(OnOffType.ON); | ||
} else { | ||
updateChannelState(OnOffType.OFF); | ||
} | ||
} | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
org.openhab.binding.zigbee/src/main/resources/OH-INF/thing/eurotronic/spzb0001.xml
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,55 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<thing:thing-descriptions bindingId="zigbee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0" | ||
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd"> | ||
|
||
<thing-type id="eurotronic_spzb0001" listed="false"> | ||
<label>Eurotronic Spirit Zigbee Thermostat</label> | ||
<description>Radiator Thermostat</description> | ||
<category>WallSwitch</category> | ||
|
||
<channels> | ||
<channel id="batteryLevel" typeId="system.battery-level"> | ||
<properties> | ||
<property name="zigbee_endpoint">1</property> | ||
</properties> | ||
</channel> | ||
<channel id="thermostat_occupiedheating" typeId="thermostat_occupiedheating"> | ||
<properties> | ||
<property name="zigbee_endpoint">1</property> | ||
</properties> | ||
</channel> | ||
<channel id="thermostat_occupiedcooling" typeId="thermostat_occupiedcooling"> | ||
<properties> | ||
<property name="zigbee_endpoint">1</property> | ||
</properties> | ||
</channel> | ||
<channel id="thermostat_unoccupiedheating" typeId="thermostat_unoccupiedheating"> | ||
<properties> | ||
<property name="zigbee_endpoint">1</property> | ||
</properties> | ||
</channel> | ||
<channel id="thermostat_heatingdemand" typeId="thermostat_heatingdemand"> | ||
<properties> | ||
<property name="zigbee_endpoint">1</property> | ||
</properties> | ||
</channel> | ||
<channel id="thermostat_systemmode" typeId="thermostat_systemmode"> | ||
<properties> | ||
<property name="zigbee_endpoint">1</property> | ||
</properties> | ||
</channel> | ||
<channel id="eurotronic_spzb0001_window_open" typeId="eurotronic_spzb0001_window_open"> | ||
<properties> | ||
<property name="zigbee_endpoint">1</property> | ||
</properties> | ||
</channel> | ||
</channels> | ||
<config-description> | ||
<parameter name="zigbee_macaddress" type="text" readOnly="true" required="true"> | ||
<label>MAC Address</label> | ||
</parameter> | ||
</config-description> | ||
</thing-type> | ||
</thing:thing-descriptions> |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There still is one issue I wasn't yet able to resolve: Sometimes the following exception occurs when enabling the handler:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly this is considered an analog attribute, in which case there is another parameter that needs to go in the reporting configuration. If the attribute is analog, and you use the digital version of this method, then I think the library will try and send the extra parameter and it will be null.