Skip to content

Commit

Permalink
V1.0.3
Browse files Browse the repository at this point in the history
- Moved the SOC and charging under the Battery Power W.
              - And cleaned up some code.
  • Loading branch information
K1LL3R234 committed Oct 11, 2024
1 parent ec6d4df commit 7d7e544
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 102 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

This change log documents all release versions of homebridge-texecom

### 1.0.3 (2024-10-11)

- **FEATURE** - Moved the SOC and charging under the Battery Power W.
- And cleaned up some code.

### 1.0.2 (2024-10-11)

- **BUG** - Fixed Not displaying something right.

### 1.0.1 (2024-10-11)

- **BUG** - Fixed bug for token being removed and can not continue requests.
Expand Down
208 changes: 112 additions & 96 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ SunsynkPlatform.prototype = {
var batt_pw = { "name": "Battery Power W", "type": "pv" };
var acc = new SunsynkAccessory(this.log, batt_pw);
allacc.push(acc);
var batt_soc = { "name": "Battery SOC", "type": "batt" };
var acc = new SunsynkAccessory(this.log, batt_soc);
allacc.push(acc);

var load_pw = { "name": "Load Power W", "type": "pv" };
var acc = new SunsynkAccessory(this.log, load_pw);
Expand All @@ -100,53 +97,51 @@ SunsynkPlatform.prototype = {

var batt_result = await api.get(`/plant/energy/${plant_id}/flow`, null, null);

for (var i = 0; i < 8; i++) {
if (allacc[i].type == 'pv') {
switch (allacc[i].name) {
case 'Current Power W':
allacc[i].changeHandler(real_result.pac);
break;

case 'Today Electricity kWh':
allacc[i].changeHandler(real_result.etoday);
break;

case 'Month Electricity kWh':
allacc[i].changeHandler(real_result.emonth);
break;

case 'Year Electricity kWh':
allacc[i].changeHandler(real_result.eyear);
break;

case 'Total Electricity kWh':
allacc[i].changeHandler(real_result.etotal);
break;

case 'Battery Power W':
allacc[i].changeHandler(batt_result.battPower);
break;

case 'Load Power W':
allacc[i].changeHandler(batt_result.loadOrEpsPower);
break;
}
}
else if (allacc[i].type == 'batt') {
allacc[i].changeHandler(batt_result.soc);
for (var i = 0; i < allacc.length; i++) {

switch (allacc[i].name) {
case 'Current Power W':
allacc[i].changeHandler(real_result.pac);
break;

case 'Today Electricity kWh':
allacc[i].changeHandler(real_result.etoday);
break;

case 'Month Electricity kWh':
allacc[i].changeHandler(real_result.emonth);
break;

case 'Year Electricity kWh':
allacc[i].changeHandler(real_result.eyear);
break;

case 'Total Electricity kWh':
allacc[i].changeHandler(real_result.etotal);
break;

var state = Characteristic.ChargingState.NOT_CHARGING;
case 'Battery Power W':
allacc[i].changeHandler(batt_result.battPower);

if (batt_result.toBat) {
state = Characteristic.ChargingState.CHARGING;
}
else if (batt_result.batTo) {
state = Characteristic.ChargingState.NOT_CHARGING;
}
allacc[i].changeHandler1(batt_result.soc);

allacc[i].changeChargeState(state);
var state = Characteristic.ChargingState.NOT_CHARGING;

allacc[i].changeLevel(batt_result.soc < lowbatt ? Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL)
if (batt_result.toBat) {
state = Characteristic.ChargingState.CHARGING;
}
else if (batt_result.batTo) {
state = Characteristic.ChargingState.NOT_CHARGING;
}

allacc[i].changeChargeState(state);

allacc[i].changeLevel(batt_result.soc < lowbatt ? Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL)
break;

case 'Load Power W':
allacc[i].changeHandler(batt_result.loadOrEpsPower);
break;
}
}
}
Expand Down Expand Up @@ -176,7 +171,7 @@ SunsynkAccessory.prototype = {
getServices: function () {
const me = this;

var service, changeAction, changeState, changeLevel;
var service, newService, changeAction, changeAction1, changeState, changeLevel;

var informationService = new Service.AccessoryInformation();

Expand All @@ -186,62 +181,83 @@ SunsynkAccessory.prototype = {
.setCharacteristic(Characteristic.Model, "Sunsynk"/*+ (this.accessoryType === ""?"":"") */)
.setCharacteristic(Characteristic.SerialNumber, this.sn);

switch (this.type) {
case "pv":
service = new Service.LightSensor();
changeAction = function (newvalue) {
service.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
.setValue(newvalue);
service.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
.updateValue(newvalue);
}
break;

case "batt":
service = new Service.Battery();
changeAction = function (newvalue) {
service.getCharacteristic(Characteristic.BatteryLevel)
.setValue(newvalue);
service.getCharacteristic(Characteristic.BatteryLevel)
.updateValue(newvalue);
}
if (this.name == 'Battery Power W') {
service = new Service.LightSensor();
newService = new Service.Battery();
changeAction = function (newvalue) {
service.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
.setValue(newvalue);
service.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
.updateValue(newvalue);
}

changeLevel = function (newlevel) {
service.getCharacteristic(Characteristic.StatusLowBattery)
.setValue(newlevel);
service.getCharacteristic(Characteristic.StatusLowBattery)
.updateValue(newlevel);
}
changeAction1 = function (newvalue) {
newService.getCharacteristic(Characteristic.BatteryLevel)
.setValue(newvalue);
newService.getCharacteristic(Characteristic.BatteryLevel)
.updateValue(newvalue);
}

changeState = function (newvalue) {
service.getCharacteristic(Characteristic.ChargingState)
.setValue(newvalue);
service.getCharacteristic(Characteristic.ChargingState)
.updateValue(newvalue);
}
break;
}
changeLevel = function (newlevel) {
newService.getCharacteristic(Characteristic.StatusLowBattery)
.setValue(newlevel);
newService.getCharacteristic(Characteristic.StatusLowBattery)
.updateValue(newlevel);
}

changeState = function (newvalue) {
newService.getCharacteristic(Characteristic.ChargingState)
.setValue(newvalue);
newService.getCharacteristic(Characteristic.ChargingState)
.updateValue(newvalue);
}

this.changeHandler = function (value) {
var newValue = value;

this.changeHandler = function (value) {
var newValue = value;
changeAction(newValue);
platform.log.debug("New Value:" + newValue);
}.bind(this);

changeAction(newValue);
platform.log.debug("New Value:" + newValue);
}.bind(this);
this.changeHandler1 = function (value) {
var newValue = value;

this.changeChargeState = function (value) {
var state = value;
changeAction1(newValue);
platform.log.debug("New Value:" + newValue);
}.bind(this);

changeState(state);
platform.log.debug("New State:" + state);
}.bind(this);
this.changeChargeState = function (value) {
var state = value;

this.changeLevel = function (value) {
var level = value;
changeLevel(level)
platform.log.debug("New Level:" + level);
}.bind(this);
changeState(state);
platform.log.debug("New State:" + state);
}.bind(this);

return [informationService, service];
this.changeLevel = function (value) {
var level = value;
changeLevel(level)
platform.log.debug("New Level:" + level);
}.bind(this);

return [informationService, service, newService];
}
else {
service = new Service.LightSensor();
changeAction = function (newvalue) {
service.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
.setValue(newvalue);
service.getCharacteristic(Characteristic.CurrentAmbientLightLevel)
.updateValue(newvalue);
}

this.changeHandler = function (value) {
var newValue = value;

changeAction(newValue);
platform.log.debug("New Value:" + newValue);
}.bind(this);

return [informationService, service];
}
}
}
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"displayName": "Homebridge Sunsynk",
"name": "homebridge-sunsynk",
"description": "A plugin for homebridge (https://github.com/nfarina/homebridge) to integrate Sunsynk inverter into HomeKit",
"version": "1.0.1",
"version": "1.0.3",
"author": {
"name": "Chris Posthumus",
"email": "[email protected]"
Expand Down Expand Up @@ -34,8 +34,7 @@
],
"engines": {
"homebridge": "^1.6.0 || ^2.0.0-beta.0",
"node": "^18.20.4 || ^20.15.1",
"python": ">=3.6.0"
"node": "^18.20.4 || ^20.15.1"
},
"homebridge": {
"platforms": [
Expand All @@ -46,8 +45,6 @@
"axios": "^0.21.1",
"crypto-js": "^4.2.0",
"debug": "^2.6.9",
"serialport": "^8.0.8",
"string": "^3.3.3",
"zpad": "^0.5.0"
"string": "^3.3.3"
}
}

0 comments on commit 7d7e544

Please sign in to comment.