Skip to content

Commit

Permalink
[solarman] Initial contribution (openhab#16835)
Browse files Browse the repository at this point in the history
* Initial commit for the Solarman Binding.

Signed-off-by: Catalin Sanda <catalin.sanda@gmail.com>
  • Loading branch information
catalinsanda authored and digitaldan committed Aug 29, 2024
1 parent c6fc4d2 commit d7ad8c5
Show file tree
Hide file tree
Showing 55 changed files with 11,589 additions and 0 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@
/bundles/org.openhab.binding.solaredge/ @alexf2015
/bundles/org.openhab.binding.solarforecast/ @weymann
/bundles/org.openhab.binding.solarlog/ @johannrichard
/bundles/org.openhab.binding.solarman/ @catalinsanda
/bundles/org.openhab.binding.solarmax/ @jamietownsend
/bundles/org.openhab.binding.solarwatt/ @sven-carstens
/bundles/org.openhab.binding.solax/ @theater
Expand Down
5 changes: 5 additions & 0 deletions bom/openhab-addons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,11 @@
<artifactId>org.openhab.binding.solarlog</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.solarman</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.solarmax</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions bundles/org.openhab.binding.solarman/NOTICE
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
290 changes: 290 additions & 0 deletions bundles/org.openhab.binding.solarman/README.md

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions bundles/org.openhab.binding.solarman/pom.xml
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>
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>
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;
}
}
}
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";
}
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;
}
}
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;
}
}
Loading

0 comments on commit d7ad8c5

Please sign in to comment.