Skip to content

Commit

Permalink
Squashed all commits
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Polihronov <polychronov@gmail.com>
  • Loading branch information
theater committed Jul 25, 2023
1 parent 51f3bf6 commit 4b938df
Show file tree
Hide file tree
Showing 26 changed files with 1,527 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 @@ -324,6 +324,7 @@
/bundles/org.openhab.binding.solarlog/ @johannrichard
/bundles/org.openhab.binding.solarmax/ @jamietownsend
/bundles/org.openhab.binding.solarwatt/ @sven-carstens
/bundles/org.openhab.binding.solax/ @theater
/bundles/org.openhab.binding.somfymylink/ @loungeflyz
/bundles/org.openhab.binding.somfytahoma/ @octa22
/bundles/org.openhab.binding.somneo/ @0x4d4d
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 @@ -1606,6 +1606,11 @@
<artifactId>org.openhab.binding.solarwatt</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.solax</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.somfymylink</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions bundles/org.openhab.binding.solax/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
210 changes: 210 additions & 0 deletions bundles/org.openhab.binding.solax/README.md

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions bundles/org.openhab.binding.solax/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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.0.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.solax</artifactId>

<name>openHAB Add-ons :: Bundles :: solax Binding</name>

<dependencies>
<!-- <dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>9.4.50.v20221201</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.11</version>
</dependency>
-->
</dependencies>
</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.solax-${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-solax" description="solax Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.solax/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2010-2023 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.solax.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.solax.internal.model.InverterData;

/**
* The {@link InverterDataUpdateListener} is used to populate updated data to the interested parties
*
* @author Konstantin Polihronov - Initial contribution
*/
@NonNullByDefault
public interface InverterDataUpdateListener {
void updateListener(InverterData data);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Copyright (c) 2010-2023 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.solax.internal;

import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID;

/**
* The {@link SolaxBindingConstants} class defines common constants, which are
* used across the whole binding.
*
* @author Konstantin Polihronov - Initial contribution
*/
@NonNullByDefault
public class SolaxBindingConstants {

private static final String BINDING_ID = "solax";
private static final String BRIDGE_LOCAL_CONNECT_ID = "localConnect";
private static final String THING_INVERTER_ID = "inverter";

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_LOCAL_CONNECT_BRIDGE = new ThingTypeUID(BINDING_ID,
BRIDGE_LOCAL_CONNECT_ID);
public static final ThingTypeUID THING_TYPE_INVERTER = new ThingTypeUID(BINDING_ID, THING_INVERTER_ID);

public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_LOCAL_CONNECT_BRIDGE,
THING_TYPE_INVERTER);

// List of all Channel ids
public static final String SERIAL_NUMBER = "serialWifi";
public static final String INVERTER_TYPE = "inverterType";

public static final String INVERTER_OUTPUT_POWER = "inverterOutputPower";
public static final String INVERTER_OUTPUT_CURRENT = "inverterCurrent";
public static final String INVERTER_OUTPUT_VOLTAGE = "inverterVoltage";
public static final String INVERTER_OUTPUT_FREQUENCY = "inverterFrequency";

public static final String INVERTER_PV1_POWER = "pv1Power";
public static final String INVERTER_PV1_VOLTAGE = "pv1Voltage";
public static final String INVERTER_PV1_CURRENT = "pv1Current";

public static final String INVERTER_PV2_POWER = "pv2Power";
public static final String INVERTER_PV2_VOLTAGE = "pv2Voltage";
public static final String INVERTER_PV2_CURRENT = "pv2Current";

public static final String INVERTER_PV_TOTAL_POWER = "pvTotalPower";
public static final String INVERTER_PV_TOTAL_CURRENT = "pvTotalCurrent";

public static final String BATTERY_POWER = "batteryPower";
public static final String BATTERY_VOLTAGE = "batteryVoltage";
public static final String BATTERY_CURRENT = "batteryCurrent";
public static final String BATTERY_TEMPERATURE = "batteryTemperature";
public static final String BATTERY_STATE_OF_CHARGE = "batteryStateOfCharge";

public static final String FEED_IN_POWER = "feedInPower";

public static final String TIMESTAMP = "lastUpdateTime";
public static final String RAW_DATA = "rawData";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* Copyright (c) 2010-2023 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.solax.internal;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.solax.internal.connectivity.LocalHttpConnector;
import org.openhab.binding.solax.internal.connectivity.rawdata.LocalConnectRawDataBean;
import org.openhab.binding.solax.internal.model.InverterData;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.binding.BaseBridgeHandler;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerService;
import org.openhab.core.types.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The {@link SolaxBridgeHandler} is responsible for handling commands, which are
* sent to one of the channels.
*
* @author Konstantin Polihronov - Initial contribution
*/
@NonNullByDefault
public class SolaxBridgeHandler extends BaseBridgeHandler {

private final Logger logger = LoggerFactory.getLogger(SolaxBridgeHandler.class);
private static final int INITIAL_SCHEDULE_DELAY_SECONDS = 5;

private SolaxConfiguration config;

private LocalHttpConnector localHttpConnector;
private Set<ScheduledFuture<?>> schedules = new HashSet<>();

public SolaxBridgeHandler(Bridge bridge) {
super(bridge);

config = getConfigAs(SolaxConfiguration.class);
localHttpConnector = new LocalHttpConnector(config.password, config.hostname);
}

@Override
public void initialize() {
logger.debug("Start initialize()...");
updateStatus(ThingStatus.UNKNOWN);

int refreshInterval = config.refresh;
TimeUnit timeUnit = TimeUnit.SECONDS;
logger.debug("Scheduling regular interval retrival on every {} {}", refreshInterval, timeUnit);
ScheduledFuture<?> fixedDelaySchedule = scheduler.scheduleWithFixedDelay(this::retrieveData,
INITIAL_SCHEDULE_DELAY_SECONDS, refreshInterval, timeUnit);
schedules.add(fixedDelaySchedule);
}

private void retrieveData() {
try {
String rawJsonData = localHttpConnector.retrieveData();
logger.debug("Raw data retrieved = {}", rawJsonData);

updateInverterData(rawJsonData);

Bridge bridge = getThing();
if (bridge.getStatus() != ThingStatus.ONLINE) {
updateStatus(ThingStatus.ONLINE);
}
} catch (IOException e) {
logger.warn("Exception received while attempting to retrieve data via HTTP", e);
updateStatus(ThingStatus.OFFLINE);
}
}

private void updateInverterData(@Nullable String rawJsonData) {
LocalConnectRawDataBean inverterParsedData = LocalConnectRawDataBean.fromJson(rawJsonData);
Bridge bridge = getThing();
List<Thing> things = bridge.getThings();
if (inverterParsedData != null) {
for (Thing thing : things) {
ThingHandler handler = thing.getHandler();
if (handler instanceof InverterDataUpdateListener listener) {
listener.updateListener(inverterParsedData);
}
}
} else {
logger.warn("Parsed bean from the raw JSON data is null. Rawdata={}", rawJsonData);
}
}

@Override
public void dispose() {
super.dispose();
schedules.forEach(schedule -> {
boolean success = schedule.cancel(true);
String cancelingSuccessful = success ? "successful" : "failed";
logger.debug("Canceling schedule of {} is {}", schedule, cancelingSuccessful);
});
}

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
// Nothing to do now
}

public @Nullable InverterData scanForInverter() throws IOException {
String rawJsonData = localHttpConnector.retrieveData();
logger.debug("Raw data retrieved = {}", rawJsonData);
return LocalConnectRawDataBean.fromJson(rawJsonData);
}

@Override
public Collection<Class<? extends ThingHandlerService>> getServices() {
return Collections.singleton(SolaxDiscoveryService.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2010-2023 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.solax.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link SolaxConfiguration} class contains fields mapping thing configuration parameters.
*
* @author Konstantin Polihronov - Initial contribution
*/
@NonNullByDefault
public class SolaxConfiguration {

public String hostname = "";
public String password = "";
public int refresh = 10;
}
Loading

0 comments on commit 4b938df

Please sign in to comment.