Skip to content

Commit 97a832d

Browse files
committed
Client: Keep track of the model year
We need this to switch between different registers for some functionalities, such as the air conditioning control.
1 parent ed8cc32 commit 97a832d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

client/client.go

+14
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ func (l *Listener) ProcessStop() bool {
4949
return false
5050
}
5151

52+
type ModelYear int64
53+
54+
const (
55+
ModelYearUnknown ModelYear = iota
56+
ModelYear14
57+
ModelYear18
58+
)
59+
5260
// A Client is a TCP client to a Phev.
5361
type Client struct {
5462
// Recv is a channel where incoming messages from the Phev are sent.
@@ -66,6 +74,9 @@ type Client struct {
6674

6775
key *protocol.SecurityKey
6876

77+
// Keep track of the model year so we can use the correct registers
78+
ModelYear ModelYear
79+
6980
closed bool
7081
}
7182

@@ -88,6 +99,7 @@ func New(opts ...Option) (*Client, error) {
8899
listeners: []*Listener{},
89100
address: DefaultAddress,
90101
key: &protocol.SecurityKey{},
102+
ModelYear: ModelYearUnknown,
91103
}
92104
for _, o := range opts {
93105
o(cl)
@@ -257,6 +269,7 @@ func (c *Client) manage() {
257269
Xor: m.Xor,
258270
}
259271
case protocol.CmdInMy18StartReq:
272+
c.ModelYear = ModelYear18
260273
c.Send <- &protocol.PhevMessage{
261274
Type: protocol.CmdOutMy18StartResp,
262275
Register: 0x1,
@@ -267,6 +280,7 @@ func (c *Client) manage() {
267280
log.Debug("%%PHEV_START18_RECV%%")
268281
c.started <- struct{}{}
269282
case protocol.CmdInMy14StartReq:
283+
c.ModelYear = ModelYear14
270284
c.Send <- &protocol.PhevMessage{
271285
Type: protocol.CmdOutMy14StartResp,
272286
Register: 0x1,

0 commit comments

Comments
 (0)