forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[jeelink] Add support for emt7110 energy meter (openhab#16725)
* feat: add support for emt7110 energy meter with jeelink Signed-off-by: tischober <t.schober@outlook.de>
- Loading branch information
Showing
10 changed files
with
321 additions
and
3 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
22 changes: 22 additions & 0 deletions
22
...eelink/src/main/java/org/openhab/binding/jeelink/internal/config/EMT7110SensorConfig.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,22 @@ | ||
/** | ||
* Copyright (c) 2010-2024 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.jeelink.internal.config; | ||
|
||
/** | ||
* Configuration for a EMT7110SensorHandler. | ||
* | ||
* @author Timo Schober - Initial contribution | ||
*/ | ||
public class EMT7110SensorConfig extends JeeLinkSensorConfig { | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
...ng.jeelink/src/main/java/org/openhab/binding/jeelink/internal/emt7110/Emt7110Reading.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,67 @@ | ||
/** | ||
* Copyright (c) 2010-2024 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.jeelink.internal.emt7110; | ||
|
||
import org.openhab.binding.jeelink.internal.Reading; | ||
|
||
/** | ||
* Handler for a EMT7110 energy Sensor thing. | ||
* | ||
* @author Timo Schober - Initial contribution | ||
*/ | ||
public class Emt7110Reading implements Reading { | ||
private final String sensorId; | ||
private final float voltage; | ||
private final float current; | ||
private final float power; | ||
private final float aPower; | ||
private final boolean on; | ||
|
||
public Emt7110Reading(String sensorId, float voltage, float current, float power, float aPower, boolean deviceOn) { | ||
this.sensorId = sensorId; | ||
this.voltage = voltage; | ||
this.current = current; | ||
this.power = power; | ||
this.aPower = aPower; | ||
this.on = deviceOn; | ||
} | ||
|
||
@Override | ||
public String getSensorId() { | ||
return sensorId; | ||
} | ||
|
||
public int getChannel() { | ||
return 0; | ||
} | ||
|
||
public float getVoltage() { | ||
return voltage; | ||
} | ||
|
||
public float getCurrent() { | ||
return current; | ||
} | ||
|
||
public boolean isOn() { | ||
return on; | ||
} | ||
|
||
public float getPower() { | ||
return power; | ||
} | ||
|
||
public float getaPower() { | ||
return aPower; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...k/src/main/java/org/openhab/binding/jeelink/internal/emt7110/Emt7110ReadingConverter.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,47 @@ | ||
/** | ||
* Copyright (c) 2010-2024 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.jeelink.internal.emt7110; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.openhab.binding.jeelink.internal.JeeLinkReadingConverter; | ||
|
||
/** | ||
* Handler for a EMT7110 energy Sensor thing. | ||
* | ||
* @author Timo Schober - Initial contribution | ||
*/ | ||
public class Emt7110ReadingConverter implements JeeLinkReadingConverter<Emt7110Reading> { | ||
private static final Pattern READING_P = Pattern.compile( | ||
"OK EMT7110\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)"); | ||
|
||
@Override | ||
public Emt7110Reading createReading(String inputLine) { | ||
// parse lines only if we have registered listeners | ||
if (inputLine != null) { | ||
Matcher matcher = READING_P.matcher(inputLine); | ||
if (matcher.matches()) { | ||
String id = matcher.group(1) + matcher.group(2); | ||
float voltage = (Integer.parseInt(matcher.group(3)) * 256 + Integer.parseInt(matcher.group(4))) / 10f; | ||
float current = (Integer.parseInt(matcher.group(5)) * 256 + Integer.parseInt(matcher.group(6))); | ||
float power = (Integer.parseInt(matcher.group(7)) * 256 + Integer.parseInt(matcher.group(8))); | ||
float aPower = (Integer.parseInt(matcher.group(9)) * 256 + Integer.parseInt(matcher.group(10))) / 100f; | ||
|
||
return new Emt7110Reading(id, voltage, current, power, aPower, true); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...k/src/main/java/org/openhab/binding/jeelink/internal/emt7110/Emt7110SensorDefinition.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,46 @@ | ||
/** | ||
* Copyright (c) 2010-2024 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.jeelink.internal.emt7110; | ||
|
||
import org.openhab.binding.jeelink.internal.JeeLinkBindingConstants; | ||
import org.openhab.binding.jeelink.internal.JeeLinkReadingConverter; | ||
import org.openhab.binding.jeelink.internal.JeeLinkSensorHandler; | ||
import org.openhab.binding.jeelink.internal.SensorDefinition; | ||
import org.openhab.core.thing.Thing; | ||
|
||
/** | ||
* Handler for a EMT7110 energy Sensor thing. | ||
* | ||
* @author Timo Schober - Initial contribution | ||
*/ | ||
public class Emt7110SensorDefinition extends SensorDefinition<Emt7110Reading> { | ||
|
||
public Emt7110SensorDefinition() { | ||
super(JeeLinkBindingConstants.EMT7110_SENSOR_THING_TYPE, "EMT7110 power monitoring wireless socket", "EMT"); | ||
} | ||
|
||
@Override | ||
public JeeLinkReadingConverter<Emt7110Reading> createConverter() { | ||
return new Emt7110ReadingConverter(); | ||
} | ||
|
||
@Override | ||
public Class<Emt7110Reading> getReadingClass() { | ||
return Emt7110Reading.class; | ||
} | ||
|
||
@Override | ||
public JeeLinkSensorHandler<Emt7110Reading> createHandler(Thing thing) { | ||
return new Emt7110SensorHandler(thing, type); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...link/src/main/java/org/openhab/binding/jeelink/internal/emt7110/Emt7110SensorHandler.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,81 @@ | ||
/** | ||
* Copyright (c) 2010-2024 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.jeelink.internal.emt7110; | ||
|
||
import static org.openhab.binding.jeelink.internal.JeeLinkBindingConstants.*; | ||
|
||
import org.openhab.binding.jeelink.internal.JeeLinkSensorHandler; | ||
import org.openhab.binding.jeelink.internal.ReadingPublisher; | ||
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.types.Command; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Handler for an EMT7110 sensor thing. | ||
* | ||
* @author Timo Schober - Initial contribution | ||
*/ | ||
public class Emt7110SensorHandler extends JeeLinkSensorHandler<Emt7110Reading> { | ||
private final Logger logger = LoggerFactory.getLogger(Emt7110SensorHandler.class); | ||
|
||
public Emt7110SensorHandler(Thing thing, String sensorType) { | ||
super(thing, sensorType); | ||
} | ||
|
||
@Override | ||
public Class<Emt7110Reading> getReadingClass() { | ||
return Emt7110Reading.class; | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
super.initialize(); | ||
|
||
logger.debug("initilized handler for thing {} ({})}", getThing().getLabel(), getThing().getUID().getId()); | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
super.dispose(); | ||
} | ||
|
||
@Override | ||
public synchronized void handleCommand(ChannelUID channelUid, Command command) { | ||
logger.debug("received command for thing {} ({}): {}", getThing().getLabel(), getThing().getUID().getId(), | ||
command); | ||
} | ||
|
||
@Override | ||
public ReadingPublisher<Emt7110Reading> createPublisher() { | ||
return new ReadingPublisher<>() { | ||
@Override | ||
public void publish(Emt7110Reading reading) { | ||
if (reading != null) { | ||
updateState(CURRENT_POWER_CHANNEL, new QuantityType<>(reading.getPower(), Units.WATT)); | ||
updateState(CONSUMPTION_CHANNEL, new QuantityType<>(reading.getaPower(), Units.KILOWATT_HOUR)); | ||
updateState(ELECTRIC_POTENTIAL_CHANNEL, new QuantityType<>(reading.getVoltage(), Units.VOLT)); | ||
updateState(ELECTRIC_CURRENT_CHANNEL, | ||
new QuantityType<>(reading.getCurrent() / 1000, Units.AMPERE)); | ||
} | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
} | ||
}; | ||
} | ||
} |
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