Skip to content

Commit

Permalink
openhab#10413 Delete commented code and Refactor Brute Force Command …
Browse files Browse the repository at this point in the history
…Discovery into something commitable

Signed-off-by: Jamie Townsend <jamie_townsend@hotmail.com>
  • Loading branch information
jamietownsend committed Apr 5, 2021
1 parent f81ff78 commit 9ddcfd6
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 166 deletions.
54 changes: 31 additions & 23 deletions bundles/org.openhab.binding.solarmax/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,37 @@ The IP address and port number (default 12345) of the device needs to be configu

## Channels

| channel | type | description |
| ------------------------ | ------ | ------------------------------------------- |
| LastUpdated | Point | When was the data last read from the device |
| SoftwareVersion | Point | Software Version installed on the SolarMax device |
| BuildNumber | Point | Firmware Build Number installed on the SolarMax device |
| Startups | Point | Number of times the device has started |
| AcPhase1Current | Point | Ac Phase 1 Current in Amps |
| AcPhase2Current | Point | Ac Phase 2 Current in Amps |
| AcPhase3Current | Point | Ac Phase 3 Current in Amps |
| EnergyGeneratedToday | Point | Energy Generated Today in wH |
| EnergyGeneratedTotal | Point | Energy Generated since recording began in wH |
| OperatingHours | Point | Operating Hours since recording began in H |
| EnergyGeneratedYesterday | Point | Energy Generated Yesterday in wH |
| EnergyGeneratedLastMonth | Point | Energy Generated Last Month in wH |
| EnergyGeneratedLastYear | Point | Energy Generated Last Year in wH |
| EnergyGeneratedThisMonth | Point | Energy Generated This Month in wH |
| EnergyGeneratedThisYear | Point | Energy Generated This Year in wH |
| Current Power Generated | Point | Power currently being generated in w |
| AcFrequency | Point | AcFrequency in Hz |
| AcPhase1Voltage | Point | Ac Phase1 Voltage in V |
| AcPhase2Voltage | Point | Ac Phase2 Voltage in V |
| AcPhase3Voltage | Point | Ac Phase3 Voltage in V |
| HeatSinkTemperature | Point | Heat Sink Temperature in degrees celcius |
| channel | type | description |
| ------------------------ | ----- | ------------------------------------------------------ |
| LastUpdated | Point | When was the data last read from the device |
| SoftwareVersion | Point | Software Version installed on the SolarMax device |
| BuildNumber | Point | Firmware Build Number installed on the SolarMax device |
| Startups | Point | Number of times the device has started |
| AcPhase1Current | Point | Ac Phase 1 Current in Amps |
| AcPhase2Current | Point | Ac Phase 2 Current in Amps |
| AcPhase3Current | Point | Ac Phase 3 Current in Amps |
| EnergyGeneratedToday | Point | Energy Generated Today in wH |
| EnergyGeneratedTotal | Point | Energy Generated since recording began in wH |
| OperatingHours | Point | Operating Hours since recording began in H |
| EnergyGeneratedYesterday | Point | Energy Generated Yesterday in wH |
| EnergyGeneratedLastMonth | Point | Energy Generated Last Month in wH |
| EnergyGeneratedLastYear | Point | Energy Generated Last Year in wH |
| EnergyGeneratedThisMonth | Point | Energy Generated This Month in wH |
| EnergyGeneratedThisYear | Point | Energy Generated This Year in wH |
| Current Power Generated | Point | Power currently being generated in w |
| AcFrequency | Point | AcFrequency in Hz |
| AcPhase1Voltage | Point | Ac Phase1 Voltage in V |
| AcPhase2Voltage | Point | Ac Phase2 Voltage in V |
| AcPhase3Voltage | Point | Ac Phase3 Voltage in V |
| HeatSinkTemperature | Point | Heat Sink Temperature in degrees celcius |

### SolarMax Commands

During the implementation the SolarMax device was sent all possible 3 character commands and a number of 4 character commands, to see what it responded to. The most interesting, identifiable and useful commands were implemented as channels above.

Here is a list of other commands, which are know to return some kind of value: ADR (DeviceAddress / Device Number - only used if the devices are linked serially), AMM, CID, CPG, CPL, CP1, CP2, CP3, CP4, CP5, CYC, DIN, DMO, ETH, FH2, FQR, FWV, IAA, IED, IEE, IEM, ILM, IP4, ISL, ITS, KFS, KHS, KTS, LAN (Language), MAC (MAC Address), PAE, PAM, PDA, PDC, PFA, PIN (Power Installed), PLR, PPC, PRL (AC Power Percent, PSF, PSR, PSS, QAC, QMO, QUC, RA1, RA2, RB1, RB2, REL, RH1, RH2, RPR, RSD, SAC, SAL, SAM, SCH, SNM (IP Broadcast Address??), SPS, SRD, SRS, SYS (Operating State), TCP (probably port number - 12345), TI1, TL1, TL3, TND, TNH, TNL, TP1, TP2, TP3, TV0, TV1, TYP (Type?), UA2, UB2, UGD, UI1, UI2, UI3, ULH, ULL, UMX, UM1, UM2, UM3, UPD, UZK, VCM

Valid commands which returned a null/empty value during testing: FFK, FRT, GCP, ITN, PLD, PLE, PLF, PLS, PPO, TV2, VLE, VLI, VLO

## Full Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
*/
public enum SolarMaxChannel {

// CHANNEL_UPDATE_VALUES_FROM_DEVICE("UpdateValuesFromDevice"),
CHANNEL_LAST_UPDATED("lastUpdated"), //
// CHANNEL_DEVICE_ADDRESS(SolarMaxCommandKey.DeviceAddress.name()),
CHANNEL_SOFTWARE_VERSION(SolarMaxCommandKey.softwareVersion.name()),
CHANNEL_BUILD_NUMBER(SolarMaxCommandKey.buildNumber.name()),
CHANNEL_STARTUPS(SolarMaxCommandKey.startups.name()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ public SolarMaxHandler(final Thing thing) {
@Override
public void handleCommand(final ChannelUID channelUID, final Command command) {
// Read only

// logger.debug("handleCommand channel: {} command: {}", channelUID, command);
// String ch = channelUID.getId();
// // if (command instanceof RefreshType) {
// // updateChannels();
// // return;
// // }
// if (ch.equals(SolarMaxChannel.CHANNEL_UPDATE_VALUES_FROM_DEVICE.name())) {
// // if (ch.equals(SolarMaxBindingConstants.CHANNEL_UPDATE_VALUES_FROM_DEVICE)) {
// updateValuesFromDevice();
// }
}

@Override
Expand Down Expand Up @@ -93,7 +82,6 @@ private void configurePolling() {
@Override
public void dispose() {
logger.debug("Disposing SolarMax Handler Thing");
// isRunning = false;
if (pollingJob != null && !pollingJob.isCancelled()) {
pollingJob.cancel(true);
}
Expand Down Expand Up @@ -137,11 +125,6 @@ private void updateChannels(SolarMaxData solarMaxData) {

Channel channel = getThing().getChannel(channelId);

// there are two special channels, where the values don't come from the device
// if (channelId.equals(SolarMaxChannel.CHANNEL_UPDATE_VALUES_FROM_DEVICE.getChannelId())) {
// // channel isn't read from the device, so ignore this

// } else
if (channelId.equals(SolarMaxChannel.CHANNEL_LAST_UPDATED.getChannelId())) {
// channel shows when the device was last read, so handle it specially
State state = solarMaxData.getDataDateTime();
Expand All @@ -155,8 +138,6 @@ private void updateChannels(SolarMaxData solarMaxData) {
if (channel == null) {
logger.error("No channel found with id: {}", channelId);
}
// State state = getState(value, channel);
// return new DecimalType(versionAsInt);
State state = solarMaxData.get(SolarMaxCommandKey.valueOf(channelId));

if (channel != null && state != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,124 +19,32 @@
*/
public enum SolarMaxCommandKey {

// for further commands, that are not implemented here, see this binding's README.md file

// Valid commands which returned a non-null value during testing
// DeviceAddress("ADR"), // device number - only used if the devices are linked serially
// UNKNOWN_AMM("AMM"), //
buildNumber("BDN"), //
startups("CAC"), //
// UNKNOWN_CID("CID"), //
// UNKNOWN_CPG("CPG"), //
// UNKNOWN_CPL("CPL"), //
// UNKNOWN_CP1("CP1"), //
// UNKNOWN_CP2("CP2"), //
// UNKNOWN_CP3("CP3"), //
// UNKNOWN_CP4("CP4"), //
// UNKNOWN_CP5("CP5"), //
// UNKNOWN_CYC("CYC"), //
// UNKNOWN_DIN("DIN"), //
// UNKNOWN_DMO("DMO"), //
// UNKNOWN_ETH("ETH"), //
// UNKNOWN_FH2("FH2"), //
// UNKNOWN_FQR("FQR"), //
// UNKNOWN_FWV("FWV"), //
// UNKNOWN_IAA("IAA"), //
// UNKNOWN_IED("IED"), //
// UNKNOWN_IEE("IEE"), //
// UNKNOWN_IEM("IEM"), //
// UNKNOWN_ILM("ILM"), //
acPhase1Current("IL1"), //
acPhase2Current("IL2"), //
acPhase3Current("IL3"), //
// UNKNOWN_IP4("IP4"), //
// UNKNOWN_ISL("ISL"), //
// UNKNOWN_ITS("ITS"), //
energyGeneratedToday("KDY"), //
// UNKNOWN_KFS("KFS"), //
operatingHours("KHR"), //
// UNKNOWN_KHS("KHS"), //
energyGeneratedYesterday("KLD"), //
energyGeneratedLastMonth("KLM"), //
energyGeneratedLastYear("KLY"), //
energyGeneratedThisMonth("KMT"), //
// UNKNOWN_KTS("KTS"), //
energyGeneratedTotal("KT0"), //
energyGeneratedThisYear("KYR"), //
// Language("LAN"), //
// MacAddress("MAC"), //
currentPowerGenerated("PAC"), //
// UNKNOWN_PAE("PAE"), //
// UNKNOWN_PAM("PAM"), //
// UNKNOWN_PDA("PDA"), //
// UNKNOWN_PDC("PDC"), //
// UNKNOWN_PFA("PFA"), //
// PowerInstalled("PIN"), //
// UNKNOWN_PLR("PLR"), //
// UNKNOWN_PPC("PPC"), //
// AcPowerPercent("PRL"), //
// UNKNOWN_PSF("PSF"), //
// UNKNOWN_PSR("PSR"), //
// UNKNOWN_PSS("PSS"), //
// UNKNOWN_QAC("QAC"), //
// UNKNOWN_QMO("QMO"), //
// UNKNOWN_QUC("QUC"), //
// UNKNOWN_RA1("RA1"), //
// UNKNOWN_RA2("RA2"), //
// UNKNOWN_RB1("RB1"), //
// UNKNOWN_RB2("RB2"), //
// UNKNOWN_REL("REL"), //
// UNKNOWN_RH1("RH1"), //
// UNKNOWN_RH2("RH2"), //
// UNKNOWN_RPR("RPR"), //
// UNKNOWN_RSD("RSD"), //
// UNKNOWN_SAC("SAC"), //
// UNKNOWN_SAL("SAL"), //
// UNKNOWN_SAM("SAM"), //
// UNKNOWN_SCH("SCH"), //
// UNKNOWN_SNM("SNM"), // IP Broadcast Address??
// UNKNOWN_SPS("SPS"), //
// UNKNOWN_SRD("SRD"), //
// UNKNOWN_SRS("SRS"), //
softwareVersion("SWV"), //
// OperatingState("SYS"), //
// UNKNOWN_TCP("TCP"), // probably port number (12345)
// UNKNOWN_TI1("TI1"), //
heatSinkTemperature("TKK"), //
// UNKNOWN_TL1("TL1"), //
// UNKNOWN_TL3("TL3"), //
// UNKNOWN_TND("TND"), //
acFrequency("TNF"), //
// UNKNOWN_TNH("TNH"), //
// UNKNOWN_TNL("TNL"), //
// UNKNOWN_TP1("TP1"), //
// UNKNOWN_TP2("TP2"), //
// UNKNOWN_TP3("TP3"), //
// UNKNOWN_TV0("TV0"), //
// UNKNOWN_TV1("TV1"), //
// Type("TYP"), //
// UNKNOWN_UA2("UA2"), //
// UNKNOWN_UB2("UB2"), //
// UNKNOWN_UGD("UGD"), //
// UNKNOWN_UI1("UI1"), //
// UNKNOWN_UI2("UI2"), //
// UNKNOWN_UI3("UI3"), //
// UNKNOWN_ULH("ULH"), //
// UNKNOWN_ULL("ULL"), //
acPhase1Voltage("UL1"), //
acPhase2Voltage("UL2"), //
acPhase3Voltage("UL3"), //
// UNKNOWN_UMX("UMX"), //
// UNKNOWN_UM1("UM1"), //
// UNKNOWN_UM2("UM2"), //
// UNKNOWN_UM3("UM3"), //
// UNKNOWN_UPD("UPD"), //
// UNKNOWN_UZK("UZK"), //
// UNKNOWN_VCM("VCM"), //
UNKNOWN("UNKNOWN") // really unknown - shouldn't ever be sent to the device
;

// Valid commands which returned a null/empty value during testing
// FFK, FRT, GCP, ITN, PLD, PLE, PLF, PLS, PPO, TV2, VLE, VLI, VLO

private String commandKey;

private SolarMaxCommandKey(String commandKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,9 @@ private static Map<SolarMaxCommandKey, String> getValuesFromSolarMax(final Outpu
String request = contructRequest(commandString);
try {

// hard code it for now
// request = "{FB;01;46|64:KDY;KMT;KYR;KT0;TNF;TKK;PAC;PRL;IL1;IDC;UL1;UDC;SYS|1199}";
// send the message out
logger.trace(" ==>: {}", request);

outputStream.write(request.getBytes());
// outputStream.flush();

String response = "";
byte[] responseByte = new byte[1];
Expand Down Expand Up @@ -360,7 +356,6 @@ static String contructRequest(final String questions) {
String dstHex = String.format("%02X", 1); // destinationDevice defaults to 1 and is ignored with TCP/IP
String len = "00";
String cs = "0000";
// String msg = is_array(questions) ? "64:" + implode(';', questions) : "64:" + questions;
String msg = "64:" + questions;
int lenInt = ("{" + src + ";" + dstHex + ";" + len + "|" + msg + "|" + cs + "}").length();

Expand Down Expand Up @@ -394,16 +389,8 @@ static String calculateChecksum16(String str) {
}

static boolean validateResponse(final String header) {

// // FIXME: 12.11.2016 whole response will be passed in
// final String patternString = "/\\{([0-9A-F]{2});FB;([0-9A-F]{2})/";
// final Pattern pattern = Pattern.compile(patternString);

// final Matcher matcher = pattern.matcher(header);

// boolean matches = matcher.matches();
// // return matches;
// // FIXME: 10.11.2016
// probably should implement a patter matcher with a patternString like "/\\{([0-9A-F]{2});FB;([0-9A-F]{2})/",
// but for now...
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<description>Basic thing for the SolarMax Power Inverter binding</description>

<channels>
<!-- <channel id="UpdateValuesFromDevice" typeId="UpdateValuesFromDevice"/> -->
<channel id="lastUpdated" typeId="lastUpdated"/>
<channel id="softwareVersion" typeId="softwareVersion"/>
<channel id="buildNumber" typeId="buildNumber"/>
Expand Down Expand Up @@ -53,12 +52,6 @@

</thing-type>

<!-- <channel-type id="UpdateValuesFromDevice">
<item-type>Switch</item-type>
<label>Update Trigger</label>
<description>Update the values from the SolarMax device</description>
</channel-type> -->

<channel-type id="lastUpdated">
<item-type>DateTime</item-type>
<label>Last Updated</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@
@NonNullByDefault
public class SolarMaxDataTest {

@Test
public void gettersTest() throws Exception {

// SolarMaxData solarMaxData = new SolarMaxData().dataDateTime()
}

@Test
public void dataDateTimeGetterSetterTest() throws Exception {

Expand Down
Loading

0 comments on commit 9ddcfd6

Please sign in to comment.