Skip to content

Commit

Permalink
feat: add version sensor and fix up some other sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
wolffshots committed Apr 9, 2024
1 parent 8247554 commit 43fa6c5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Print event JSON
run: cat $GITHUB_EVENT_PATH

- name: Cache Go modules
uses: actions/cache@v4
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/svelte.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Print event JSON
run: cat $GITHUB_EVENT_PATH

- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
Expand Down
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
serial "github.com/wolffshots/phocus/v2/serial" // comms with inverter
)

const version = "v2.11.0"
const version = "v2.11.1"

type Configuration struct {
Serial struct {
Expand Down Expand Up @@ -101,6 +101,12 @@ func main() {
log.Printf("Failed to clear previous error: %v\n", pubErr)
}

// send new version
pubErr = mqtt.Send(client, "phocus/stats/version", 0, false, version, 10)
if pubErr != nil {
log.Printf("Failed to set phocus version: %v\n", pubErr)
}

// serial
port, err := serial.Setup(
configuration.Serial.Port,
Expand Down
23 changes: 17 additions & 6 deletions sensors/sensors.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ type Sensor struct {
}

var sensors = []Sensor{
{
SensorTopic: "homeassistant/sensor/phocus/version/config",
UniqueId: "phocus_version",
Unit: units.None,
StateClass: state_classes.None,
DeviceClass: device_classes.None,
Name: "Phocus Version",
ValueTemplate: "",
StateTopic: "phocus/stats/version",
Icon: "mdi:source-branch",
},
{
SensorTopic: "homeassistant/sensor/phocus/start_time/config",
UniqueId: "phocus_start_time",
Expand Down Expand Up @@ -212,7 +223,7 @@ var sensors = []Sensor{
Name: "QPGS1 PV Input Current",
ValueTemplate: "{{ value_json.PVInputCurrent }}",
StateTopic: "phocus/stats/qpgs1",
Icon: "mdi:current",
Icon: "mdi:current-dc",
},
{
SensorTopic: "homeassistant/sensor/phocus/qpgs2_pv_input_current/config",
Expand All @@ -223,7 +234,7 @@ var sensors = []Sensor{
Name: "QPGS2 PV Input Current",
ValueTemplate: "{{ value_json.PVInputCurrent }}",
StateTopic: "phocus/stats/qpgs2",
Icon: "mdi:current",
Icon: "mdi:current-dc",
},
{
SensorTopic: "homeassistant/sensor/phocus/qpgs1_battery_discharge_current/config",
Expand All @@ -234,7 +245,7 @@ var sensors = []Sensor{
Name: "QPGS1 Battery Discharge Current",
ValueTemplate: "{{ value_json.BatteryDischargeCurrent }}",
StateTopic: "phocus/stats/qpgs1",
Icon: "mdi:current",
Icon: "mdi:current-dc",
},
{
SensorTopic: "homeassistant/sensor/phocus/qpgs2_battery_discharge_current/config",
Expand All @@ -245,7 +256,7 @@ var sensors = []Sensor{
Name: "QPGS2 Battery Discharge Current",
ValueTemplate: "{{ value_json.BatteryDischargeCurrent }}",
StateTopic: "phocus/stats/qpgs2",
Icon: "mdi:current",
Icon: "mdi:current-dc",
},
{
SensorTopic: "homeassistant/sensor/phocus/qpgs1_battery_charge_current/config",
Expand All @@ -256,7 +267,7 @@ var sensors = []Sensor{
Name: "QPGS1 Battery Charge Current",
ValueTemplate: "{{ value_json.BatteryChargingCurrent }}",
StateTopic: "phocus/stats/qpgs1",
Icon: "mdi:current",
Icon: "mdi:current-dc",
},
{
SensorTopic: "homeassistant/sensor/phocus/qpgs2_battery_charge_current/config",
Expand All @@ -267,7 +278,7 @@ var sensors = []Sensor{
Name: "QPGS2 Battery Charge Current",
ValueTemplate: "{{ value_json.BatteryChargingCurrent }}",
StateTopic: "phocus/stats/qpgs2",
Icon: "mdi:current",
Icon: "mdi:current-dc",
},
{
SensorTopic: "homeassistant/sensor/phocus/qpgs1_ac_input_mode/config",
Expand Down

0 comments on commit 43fa6c5

Please sign in to comment.