-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[openwebnet] add support for Energy Meter #10191
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2bb6e38
Merge pull request #1 from openhab/main
aconte80 0a89dc5
add support for Energy Management #10189
aconte80 d93eb7b
Merge pull request #2 from openhab/main
aconte80 d3d270a
fixed code-review suggestions
aconte80 f4cbb11
fixed code-review suggestions #2
aconte80 b247b83
removed initialize() and dispose() override
aconte80 824a939
redo mvn:spotless apply
aconte80 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
113 changes: 113 additions & 0 deletions
113
...nwebnet/src/main/java/org/openhab/binding/openwebnet/handler/OpenWebNetEnergyHandler.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,113 @@ | ||
/** | ||
* Copyright (c) 2010-2021 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.openwebnet.handler; | ||
|
||
import static org.openhab.binding.openwebnet.OpenWebNetBindingConstants.CHANNEL_POWER; | ||
|
||
import java.util.Set; | ||
|
||
import javax.measure.quantity.Power; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.binding.openwebnet.OpenWebNetBindingConstants; | ||
import org.openhab.core.library.types.QuantityType; | ||
import org.openhab.core.library.unit.Units; | ||
import org.openhab.core.thing.ChannelUID; | ||
import org.openhab.core.thing.Thing; | ||
import org.openhab.core.thing.ThingTypeUID; | ||
import org.openhab.core.types.Command; | ||
import org.openhab.core.types.UnDefType; | ||
import org.openwebnet4j.communication.OWNException; | ||
import org.openwebnet4j.message.BaseOpenMessage; | ||
import org.openwebnet4j.message.EnergyManagement; | ||
import org.openwebnet4j.message.FrameException; | ||
import org.openwebnet4j.message.Where; | ||
import org.openwebnet4j.message.WhereEnergyManagement; | ||
import org.openwebnet4j.message.Who; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The {@link OpenWebNetEnergyHandler} is responsible for handling commands/messages for a Energy Management OpenWebNet | ||
* device. It extends the abstract {@link OpenWebNetThingHandler}. | ||
* | ||
* @author Massimo Valla - Initial contribution | ||
* @author Andrea Conte - Energy management | ||
*/ | ||
@NonNullByDefault | ||
public class OpenWebNetEnergyHandler extends OpenWebNetThingHandler { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(OpenWebNetEnergyHandler.class); | ||
|
||
public final static Set<ThingTypeUID> SUPPORTED_THING_TYPES = OpenWebNetBindingConstants.ENERGY_MANAGEMENT_SUPPORTED_THING_TYPES; | ||
|
||
public OpenWebNetEnergyHandler(Thing thing) { | ||
super(thing); | ||
} | ||
|
||
@Override | ||
protected Where buildBusWhere(String wStr) throws IllegalArgumentException { | ||
return new WhereEnergyManagement(wStr); | ||
} | ||
|
||
@Override | ||
protected void requestChannelState(ChannelUID channel) { | ||
logger.debug("requestChannelState() thingUID={} channel={}", thing.getUID(), channel.getId()); | ||
try { | ||
bridgeHandler.gateway.send(EnergyManagement.requestActivePower(deviceWhere.value())); | ||
} catch (OWNException e) { | ||
logger.warn("requestChannelState() OWNException thingUID={} channel={}: {}", thing.getUID(), | ||
channel.getId(), e.getMessage()); | ||
} | ||
} | ||
|
||
@Override | ||
protected void handleChannelCommand(ChannelUID channel, Command command) { | ||
logger.warn("handleChannelCommand() Read only channel, unsupported command {}", command); | ||
} | ||
|
||
@Override | ||
protected String ownIdPrefix() { | ||
return Who.ENERGY_MANAGEMENT.value().toString(); | ||
} | ||
|
||
@Override | ||
protected void handleMessage(BaseOpenMessage msg) { | ||
super.handleMessage(msg); | ||
|
||
if (msg.isCommand()) { | ||
logger.warn("handleMessage() Ignoring unsupported command for thing {}. Frame={}", getThing().getUID(), | ||
msg); | ||
return; | ||
} else { | ||
updateActivePower(msg); | ||
} | ||
} | ||
|
||
/** | ||
* Updates energy power state based on a EnergyManagement message received from the OWN network | ||
* | ||
* @param msg the EnergyManagement message received | ||
* @throws FrameException | ||
*/ | ||
private void updateActivePower(BaseOpenMessage msg) { | ||
Integer activePower; | ||
try { | ||
activePower = Integer.parseInt(msg.getDimValues()[0]); | ||
updateState(CHANNEL_POWER, new QuantityType<Power>(activePower, Units.WATT)); | ||
} catch (FrameException e) { | ||
logger.warn("FrameException on frame {}: {}", msg, e.getMessage()); | ||
updateState(CHANNEL_POWER, UnDefType.UNDEF); | ||
} | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/thing/BusEnergyMeter.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,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<thing:thing-descriptions bindingId="openwebnet" | ||
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 for BUS Energy Management Central Unit (BTicino F52x) --> | ||
<thing-type id="bus_energy_meter"> | ||
<supported-bridge-type-refs> | ||
<bridge-type-ref id="bus_gateway"/> | ||
</supported-bridge-type-refs> | ||
|
||
<label>Energy Meter</label> | ||
<description>A OpenWebNet BUS/SCS Energy Meter. BTicino models: F52x</description> | ||
|
||
<channels> | ||
<channel id="power" typeId="power"/> | ||
</channels> | ||
|
||
<properties> | ||
<property name="vendor">BTicino/Legrand</property> | ||
<property name="model">BTI-F52x</property> | ||
<property name="ownDeviceType">1830</property> | ||
</properties> | ||
|
||
<representation-property>ownId</representation-property> | ||
|
||
<config-description> | ||
<parameter name="where" type="text" required="true"> | ||
<label>OpenWebNet Address</label> | ||
<description>Example: 5N with N=[1-255]</description> | ||
</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
Oops, something went wrong.
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.
This should make it resolve from our Artifactory for now.