Class: MideaAirCondition::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/client.rb

Overview

Client for Midea AC server

Constant Summary collapse

SERVER_URL =
'https://mapp.appsmb.com/v1'
CLIENT_TYPE =

Android

1
FORMAT =

JSON

2
LANGUAGE =
'en_US'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, password, app_key:, app_id: 1017, src: 17) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/client.rb', line 18

def initialize(email, password, app_key:, app_id: 1017, src: 17)
  @app_id   = app_id
  @src      = src
  @email    = email
  @password = password
  @app_key  = app_key
  @debug    = false

  @security = Security.new(app_key: @app_key)

  @current = nil
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



16
17
18
# File 'lib/client.rb', line 16

def debug
  @debug
end

Instance Method Details

#appliance_listObject



43
44
45
46
47
48
49
# File 'lib/client.rb', line 43

def appliance_list
  response = api_request(
    'appliance/list/get',
    homegroupId: default_home['id']
  )
  response['list']
end

#appliance_transparent_send(appliance_id, data) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/client.rb', line 51

def appliance_transparent_send(appliance_id, data)
  response = api_request(
    'appliance/transparent/send',
    order: encode(@security.transcode(data).join(',')),
    funId: '0000',
    applianceId: appliance_id
  )

  response = decode(response['reply']).split(',').map { |p| p.to_i & 0xff }

  response
end

#loginObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/client.rb', line 31

def 
   = ['loginId']

  encrypted_password = @security.encrypt_password(@password, )
  @current = api_request(
    'user/login',
    loginAccount: @email,
    password: encrypted_password
  )
  @security.access_token = @current['accessToken']
end

#new_packet_builderObject



64
65
66
# File 'lib/client.rb', line 64

def new_packet_builder
  PacketBuilder.new(@security)
end