-
-
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.
[solarman] Initial contribution (#16835)
* Initial commit for the Solarman Binding. Signed-off-by: Catalin Sanda <catalin.sanda@gmail.com>
- Loading branch information
1 parent
7baec4d
commit 1cd7a4f
Showing
55 changed files
with
11,589 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
This content is produced and maintained by the openHAB project. | ||
|
||
* Project home: https://www.openhab.org | ||
|
||
== Declared Project Licenses | ||
|
||
This program and the accompanying materials are made available under the terms | ||
of the Eclipse Public License 2.0 which is available at | ||
https://www.eclipse.org/legal/epl-2.0/. | ||
|
||
== Source Code | ||
|
||
https://github.com/openhab/openhab-addons |
Large diffs are not rendered by default.
Oops, something went wrong.
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.openhab.addons.bundles</groupId> | ||
<artifactId>org.openhab.addons.reactor.bundles</artifactId> | ||
<version>4.3.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>org.openhab.binding.solarman</artifactId> | ||
|
||
<name>openHAB Add-ons :: Bundles :: Solarman Binding</name> | ||
|
||
</project> |
9 changes: 9 additions & 0 deletions
9
bundles/org.openhab.binding.solarman/src/main/feature/feature.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,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<features name="org.openhab.binding.solarman-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0"> | ||
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository> | ||
|
||
<feature name="openhab-binding-solarman" description="Solarman Binding" version="${project.version}"> | ||
<feature>openhab-runtime-base</feature> | ||
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.solarman/${project.version}</bundle> | ||
</feature> | ||
</features> |
62 changes: 62 additions & 0 deletions
62
...inding.solarman/src/main/java/org/openhab/binding/solarman/internal/DefinitionParser.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,62 @@ | ||
/** | ||
* 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.solarman.internal; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.binding.solarman.internal.defmodel.InverterDefinition; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
|
||
/** | ||
* The {@link DefinitionParser} is parses inverter definitions | ||
* | ||
* @author Catalin Sanda - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class DefinitionParser { | ||
private final Logger logger = LoggerFactory.getLogger(DefinitionParser.class); | ||
|
||
private final ObjectMapper mapper; | ||
|
||
public DefinitionParser() { | ||
mapper = new ObjectMapper(new YAMLFactory()); | ||
} | ||
|
||
@Nullable | ||
public InverterDefinition parseDefinition(String definitionId) { | ||
ClassLoader cl = Objects.requireNonNull(getClass().getClassLoader()); | ||
String definitionFileName = String.format("definitions/%s.yaml", definitionId); | ||
try (InputStream is = cl.getResourceAsStream(definitionFileName)) { | ||
if (is == null) { | ||
logger.warn("Unable to read definition file {}", definitionFileName); | ||
return null; | ||
} | ||
|
||
InverterDefinition inverterDefinition = mapper.readValue(is, InverterDefinition.class); | ||
inverterDefinition.setInverterDefinitionId(definitionId); | ||
|
||
return inverterDefinition; | ||
} catch (IOException e) { | ||
logger.warn("Error parsing definition with ID: {}", definitionId, e); | ||
return null; | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...olarman/src/main/java/org/openhab/binding/solarman/internal/SolarmanBindingConstants.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,30 @@ | ||
/** | ||
* 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.solarman.internal; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.openhab.core.thing.ThingTypeUID; | ||
|
||
/** | ||
* The {@link SolarmanBindingConstants} class defines common constants, which are | ||
* used across the whole binding. | ||
* | ||
* @author Catalin Sanda - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class SolarmanBindingConstants { | ||
|
||
public static final String SOLARMAN_BINDING_ID = "solarman"; | ||
public static final ThingTypeUID THING_TYPE_SOLARMAN_LOGGER = new ThingTypeUID(SOLARMAN_BINDING_ID, "logger"); | ||
public static final String DYNAMIC_CHANNEL = "dynamic-channel"; | ||
} |
53 changes: 53 additions & 0 deletions
53
....solarman/src/main/java/org/openhab/binding/solarman/internal/SolarmanHandlerFactory.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,53 @@ | ||
/** | ||
* 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.solarman.internal; | ||
|
||
import java.util.Set; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.core.thing.Thing; | ||
import org.openhab.core.thing.ThingTypeUID; | ||
import org.openhab.core.thing.binding.BaseThingHandlerFactory; | ||
import org.openhab.core.thing.binding.ThingHandler; | ||
import org.openhab.core.thing.binding.ThingHandlerFactory; | ||
import org.osgi.service.component.annotations.Component; | ||
|
||
/** | ||
* The {@link SolarmanHandlerFactory} is responsible for creating things and thing | ||
* handlers. | ||
* | ||
* @author Catalin Sanda - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
@Component(configurationPid = "binding.solarman", service = ThingHandlerFactory.class) | ||
public class SolarmanHandlerFactory extends BaseThingHandlerFactory { | ||
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set | ||
.of(SolarmanBindingConstants.THING_TYPE_SOLARMAN_LOGGER); | ||
|
||
@Override | ||
public boolean supportsThingType(ThingTypeUID thingTypeUID) { | ||
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID); | ||
} | ||
|
||
@Override | ||
protected @Nullable ThingHandler createHandler(Thing thing) { | ||
ThingTypeUID thingTypeUID = thing.getThingTypeUID(); | ||
|
||
if (SolarmanBindingConstants.THING_TYPE_SOLARMAN_LOGGER.equals(thingTypeUID)) { | ||
return new SolarmanLoggerHandler(thing); | ||
} | ||
|
||
return null; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...rman/src/main/java/org/openhab/binding/solarman/internal/SolarmanLoggerConfiguration.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,74 @@ | ||
/** | ||
* 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.solarman.internal; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
|
||
/** | ||
* The {@link SolarmanLoggerConfiguration} class contains fields mapping thing configuration parameters. | ||
* | ||
* @author Catalin Sanda - Initial contribution | ||
*/ | ||
@NonNullByDefault | ||
public class SolarmanLoggerConfiguration { | ||
|
||
/** | ||
* Solarman Logger Thing Configuration Parameters | ||
*/ | ||
public String hostname = ""; | ||
public Integer port = 8899; | ||
public String serialNumber = ""; | ||
public String inverterType = "sg04lp3"; | ||
public int refreshInterval = 30; | ||
@Nullable | ||
public String additionalRequests; | ||
|
||
public SolarmanLoggerConfiguration() { | ||
} | ||
|
||
public SolarmanLoggerConfiguration(String hostname, Integer port, String serialNumber, String inverterType, | ||
int refreshInterval, @Nullable String additionalRequests) { | ||
this.hostname = hostname; | ||
this.port = port; | ||
this.serialNumber = serialNumber; | ||
this.inverterType = inverterType; | ||
this.refreshInterval = refreshInterval; | ||
this.additionalRequests = additionalRequests; | ||
} | ||
|
||
public String getHostname() { | ||
return hostname; | ||
} | ||
|
||
public Integer getPort() { | ||
return port; | ||
} | ||
|
||
public String getSerialNumber() { | ||
return serialNumber; | ||
} | ||
|
||
public String getInverterType() { | ||
return inverterType; | ||
} | ||
|
||
public int getRefreshInterval() { | ||
return refreshInterval; | ||
} | ||
|
||
@Nullable | ||
public String getAdditionalRequests() { | ||
return additionalRequests; | ||
} | ||
} |
Oops, something went wrong.