Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package/heishamon/files/config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mqttPass: ""
mqttKeepalive: 60
mqttTopicBase: "panasonic_heat_pump"
haAutoDiscover: true
decodeEnums: true
logmqtt: true
loghex: false
logdebug: false
8 changes: 6 additions & 2 deletions package/heishamon/src/codec/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func convertIntToEnum(value int, topic *topics.TopicEntry) string {

// Decode decodes a byte slice received from the heat pump into a TopicData structure.
// The returned value is a slice containing all TopicEntry records that have changed as a result of decoding.
func Decode(allTopics *topics.TopicData, data []byte) []*topics.TopicEntry {
func Decode(allTopics *topics.TopicData, data []byte, decodeEnums bool) []*topics.TopicEntry {
changed := make([]*topics.TopicEntry, 0, len(allTopics.GetAll()))
for _, v := range allTopics.GetAll() {
if !v.Readable() {
Expand All @@ -193,7 +193,11 @@ func Decode(allTopics *topics.TopicData, data []byte) []*topics.TopicEntry {
if byteOperator, ok := decodeToInt[decode.DecodeFunction]; ok {
decoded := byteOperator(data[decode.Offset])
floatValue += float64(decoded)
topicValue = convertIntToEnum(decoded, v)
if decodeEnums {
topicValue = convertIntToEnum(decoded, v)
} else {
topicValue = fmt.Sprintf("%d", decoded)
}
} else if floatOperator, ok := decodeToFloat[decode.DecodeFunction]; ok {
floatValue += floatOperator(data[decode.Offset])
topicValue = fmt.Sprintf("%.2f", floatValue)
Expand Down
118 changes: 83 additions & 35 deletions package/heishamon/src/codec/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestDecode(t *testing.T) {
topics := topics.LoadTopics("../../files/topics.yaml", "TestDevice", topics.Main)
topicData := topics.LoadTopics("../../files/topics.yaml", "TestDevice", topics.Main)

command := []byte{
0x71, 0xC8, 0x01, 0x10, 0x56, 0x55, 0x61, 0x49, 0x00, 0x55,
Expand Down Expand Up @@ -40,46 +40,94 @@ func TestDecode(t *testing.T) {
command[170] = 25 // pump flow 25
command[22] = 0x14 // Z1 - thermistor, Z2 - water temp

Decode(topics, command)
holi, _ := topics.Lookup("Holiday_Mode_State")
t.Logf("Holiday_Mode_State %s", holi.CurrentValue())
if holi.CurrentValue() != "Scheduled" {
t.Error("Holiday_Mode_State decode error")
}
Decode(topicData, command, true)
{
holi, _ := topicData.Lookup("Holiday_Mode_State")
t.Logf("Holiday_Mode_State %s", holi.CurrentValue())
if holi.CurrentValue() != "Scheduled" {
t.Error("Holiday_Mode_State decode error")
}

dhw, _ := topics.Lookup("DHW_Heat_Delta")
t.Logf("DHW_Heat_Delta %s", dhw.CurrentValue())
if dhw.CurrentValue() != "-5" {
t.Errorf("DHW_Heat_Delta decode error: %s", dhw.CurrentValue())
}
dhw, _ := topicData.Lookup("DHW_Heat_Delta")
t.Logf("DHW_Heat_Delta %s", dhw.CurrentValue())
if dhw.CurrentValue() != "-5" {
t.Errorf("DHW_Heat_Delta decode error: %s", dhw.CurrentValue())
}

inlet, _ := topics.Lookup("Main_Inlet_Temp")
t.Logf("Main_Inlet_Temp %s", inlet.CurrentValue())
if inlet.CurrentValue() != "22.50" {
t.Error("Wrong inlet temp")
}
inlet, _ := topicData.Lookup("Main_Inlet_Temp")
t.Logf("Main_Inlet_Temp %s", inlet.CurrentValue())
if inlet.CurrentValue() != "22.50" {
t.Error("Wrong inlet temp")
}

pumpFlow, _ := topics.Lookup("Pump_Flow")
t.Logf("Pump_Flow %s", pumpFlow.CurrentValue())
if pumpFlow.CurrentValue() != "25.22" {
t.Error("Pump_Flow decode error")
}
pumpFlow, _ := topicData.Lookup("Pump_Flow")
t.Logf("Pump_Flow %s", pumpFlow.CurrentValue())
if pumpFlow.CurrentValue() != "25.22" {
t.Error("Pump_Flow decode error")
}

z1set, _ := topics.Lookup("Z1_Sensor_Settings")
t.Logf("Z1_Sensor_Settings %s", z1set.CurrentValue())
if z1set.CurrentValue() != "Thermistor" {
t.Error("Z1_Sensor_Settings decode error")
}
z1set, _ := topicData.Lookup("Z1_Sensor_Settings")
t.Logf("Z1_Sensor_Settings %s", z1set.CurrentValue())
if z1set.CurrentValue() != "Thermistor" {
t.Error("Z1_Sensor_Settings decode error")
}

z2set, _ := topicData.Lookup("Z2_Sensor_Settings")
t.Logf("Z2_Sensor_Settings %s", z2set.CurrentValue())
if z2set.CurrentValue() != "Water temperature" {
t.Error("Z2_Sensor_Settings decode error")
}

z2set, _ := topics.Lookup("Z2_Sensor_Settings")
t.Logf("Z2_Sensor_Settings %s", z2set.CurrentValue())
if z2set.CurrentValue() != "Water temperature" {
t.Error("Z2_Sensor_Settings decode error")
model, _ := topicData.Lookup("Heat_Pump_Model")
t.Logf("Heat_Pump_Model %s", model.CurrentValue())
if model.CurrentValue() != "IDU: Monoblock ODU: WH-MXC09J3E8" {
t.Error("Unexpected heat pump model")
}
}

model, _ := topics.Lookup("Heat_Pump_Model")
t.Logf("Heat_Pump_Model %s", model.CurrentValue())
if model.CurrentValue() != "IDU: Monoblock ODU: WH-MXC09J3E8" {
t.Error("Unexpected heat pump model")
// test raw values
Decode(topicData, command, false)
{
holi, _ := topicData.Lookup("Holiday_Mode_State")
t.Logf("Holiday_Mode_State %s", holi.CurrentValue())
if holi.CurrentValue() != "1" {
t.Error("Holiday_Mode_State decode error")
}

dhw, _ := topicData.Lookup("DHW_Heat_Delta")
t.Logf("DHW_Heat_Delta %s", dhw.CurrentValue())
if dhw.CurrentValue() != "-5" {
t.Errorf("DHW_Heat_Delta decode error: %s", dhw.CurrentValue())
}

inlet, _ := topicData.Lookup("Main_Inlet_Temp")
t.Logf("Main_Inlet_Temp %s", inlet.CurrentValue())
if inlet.CurrentValue() != "22.50" {
t.Error("Wrong inlet temp")
}

pumpFlow, _ := topicData.Lookup("Pump_Flow")
t.Logf("Pump_Flow %s", pumpFlow.CurrentValue())
if pumpFlow.CurrentValue() != "25.22" {
t.Error("Pump_Flow decode error")
}

z1set, _ := topicData.Lookup("Z1_Sensor_Settings")
t.Logf("Z1_Sensor_Settings %s", z1set.CurrentValue())
if z1set.CurrentValue() != "3" {
t.Error("Z1_Sensor_Settings decode error")
}

z2set, _ := topicData.Lookup("Z2_Sensor_Settings")
t.Logf("Z2_Sensor_Settings %s", z2set.CurrentValue())
if z2set.CurrentValue() != "0" {
t.Error("Z2_Sensor_Settings decode error")
}

model, _ := topicData.Lookup("Heat_Pump_Model")
t.Logf("Heat_Pump_Model %s", model.CurrentValue())
if model.CurrentValue() != "IDU: Monoblock ODU: WH-MXC09J3E8" {
t.Error("Unexpected heat pump model")
}
}
}
18 changes: 18 additions & 0 deletions package/heishamon/src/codec/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ func TestEncode(t *testing.T) {
t.Error("Holiday_Mode_State encode error")
}

holi.UpdateValue("0")
encode(holi, command)
if command[5] != 16 {
t.Error("Holiday_Mode_State encode error")
}

holi.UpdateValue("1")
encode(holi, command)
if command[5] != 32 {
t.Error("Holiday_Mode_State encode error")
}

holi.UpdateValue("2")
encode(holi, command)
if command[5] != 48 {
t.Error("Holiday_Mode_State encode error")
}

dhw, _ := topics.Lookup("DHW_Heat_Delta")
dhw.UpdateValue("-5")
encode(dhw, command)
Expand Down
1 change: 1 addition & 0 deletions package/heishamon/src/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type configStruct struct {
MqttKeepalive int `yaml:"mqttKeepalive"`
MqttTopicBase string `yaml:"mqttTopicBase"`
HAAutoDiscover bool `yaml:"haAutoDiscover"`
DecodeEnums bool `yaml:"decodeEnums"`

LogMqtt bool `yaml:"logmqtt"`
LogHexDump bool `yaml:"loghex"`
Expand Down
4 changes: 2 additions & 2 deletions package/heishamon/src/taw2mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ func main() {
}
switch {
case len(data) == serial.OptionalMessageLength:
values := codec.Decode(optionalPCBTopics, data)
values := codec.Decode(optionalPCBTopics, data, config.DecodeEnums)
for _, v := range values {
mclient.PublishValue(v)
}
acknowledgeChannel <- data
case len(data) == serial.DataMessageLength:
values := codec.Decode(commandTopics, data)
values := codec.Decode(commandTopics, data, config.DecodeEnums)
for _, v := range values {
mclient.PublishValue(v)
}
Expand Down