Skip to content

Commit

Permalink
Fix signal
Browse files Browse the repository at this point in the history
  • Loading branch information
Laica-Lunasys committed Apr 10, 2024
1 parent 559cdcd commit 9371991
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
32 changes: 7 additions & 25 deletions aircon/mitsubishi/sc4ua/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,52 @@ func (r *sc4ua) Generate(req *appliances.Request) ([]*hex.HexCode, error) {
e := req.Aircon()
code := [][]int{
{0x23, 0xCB, 0x26, 0x21, 0x03},
{0x23, 0xCB, 0x26, 0x21, 0x03, 0x60, 0x01, 0x00, 0x04, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFB, 0xFF, 0xFF},
{0x23, 0xCB, 0x26, 0x21, 0x03, 0x60, 0x01, 0x00, 0x04, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
}

// Operation
if e.Operation {
code[1][5] = 0x60
code[1][11] -= 0x60
} else {
code[1][5] = 0x20
code[1][11] -= 0x20
}

// Mode
switch e.Mode {
case "auto":
code[1][6] = 0x03
code[1][12] = 0xFC
case "cool":
code[1][6] = 0x01
code[1][12] = 0xFE
case "dry":
code[1][6] = 0x05
code[1][12] = 0xFA
case "heat":
code[1][6] = 0x02
code[1][12] = 0xFD
case "fan":
code[1][6] = 0x00
code[1][12] = 0xFF
}

// Temp
if e.Mode == "auto" || e.Mode == "cool" || e.Mode == "dry" || e.Mode == "heat" {
temp := e.Temp.(float64)
t := (int(temp*10) - 160) / 5
code[1][5] += t
code[1][11] -= t
} else {
// code[1][4] = 0x00
code[1][5] = 0x74
code[1][11] = 0xFF - 0x74
code[1][5] += 0x14
}

// Fan
switch e.Fan {
case "auto":
code[1][7] += 0x09
code[1][13] -= 0x09
case "1":
code[1][7] += 0x01
code[1][13] -= 0x01
case "2":
code[1][7] += 0x03
code[1][13] -= 0x03
case "3":
code[1][7] += 0x05
code[1][13] -= 0x05
case "4":
code[1][7] += 0x07
code[1][13] -= 0x07
default:
return nil, errors.New("invalid fan provided")
}
Expand All @@ -79,25 +65,18 @@ func (r *sc4ua) Generate(req *appliances.Request) ([]*hex.HexCode, error) {
switch e.HorizontalVane {
case "auto":
code[1][7] += 0x60
code[1][13] -= 0x60
case "swing":
code[1][7] += 0x40
code[1][13] -= 0x40
case "1":
code[1][7] += 0x30
code[1][13] -= 0x30
case "2":
code[1][7] += 0x50
code[1][13] -= 0x50
case "3":
code[1][7] += 0x20
code[1][13] -= 0x20
case "4":
code[1][7] += 0x10
code[1][13] -= 0x10
case "5":
code[1][7] += 0x00
code[1][13] -= 0x00

default:
return nil, errors.New("invalid horizontal_vane proided")
Expand All @@ -107,14 +86,17 @@ func (r *sc4ua) Generate(req *appliances.Request) ([]*hex.HexCode, error) {
switch e.VerticalVane {
case "keep":
// code[1][7] += 0x00
// code[1][13] -= 0x00
case "swing":
code[1][7] += 0x80
code[1][13] -= 0x80
default:
return nil, errors.New("invalid vertical_vane provided")
}

// Checksum
for i := 5; i <= 10; i++ {
code[1][6+i] -= code[1][i]
}

return []*hex.HexCode{
{
Code: code,
Expand Down
22 changes: 21 additions & 1 deletion aircon/mitsubishi/sc4ua/entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/dash-app/remote-go/test"
)

func Test_Mitsubishi02(t *testing.T) {
func Test_Mitsubishi_SC4UA(t *testing.T) {
rem := sc4ua.New()
tmpl := rem.Template().Aircon

Expand Down Expand Up @@ -292,6 +292,26 @@ func Test_Mitsubishi02(t *testing.T) {
VerticalVane: tmpl.Modes["cool"].VerticalVane.Default.(string),
}),
},
{
Title: "Auto/HorizontalVane=Swing",
Remote: rem,
Original: []*test.Original{
{
Code: [][]int{
{0x23, 0xCB, 0x26, 0x21, 0x03},
{0x23, 0xCB, 0x26, 0x21, 0x03, 0x74, 0x03, 0x49, 0x04, 0x00, 0x00, 0x8B, 0xFC, 0xB6, 0xFB, 0xFF, 0xFF},
},
},
},
Request: appliances.FromAircon(&appliances.Aircon{
Operation: true,
Mode: "auto",
Temp: tmpl.Modes["auto"].Temp.Default,
Fan: tmpl.Modes["auto"].Fan.Default.(string),
HorizontalVane: "swing",
VerticalVane: tmpl.Modes["auto"].VerticalVane.Default.(string),
}),
},
{
Title: "Cool/VerticalVane=swing",
Remote: rem,
Expand Down
2 changes: 1 addition & 1 deletion aircon/mitsubishi/sc4ua/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var Template = &appliances.Template{
Vendor: "mitsubishi",
Model: "02",
Model: "PAR-SC4UA",
Kind: appliances.AIRCON,
Aircon: &appliances.AirconTemplate{
Operation: &appliances.ActionTemplate{
Expand Down

0 comments on commit 9371991

Please sign in to comment.