Class: E3DCMqtt::RSCP::Client
- Inherits:
-
Object
- Object
- E3DCMqtt::RSCP::Client
- Defined in:
- lib/e3dc_mqtt/rscp/client.rb
Overview
Authenticated, encrypted connection to an E3DC system over RSCP.
Usage:
client = Client.new(host:, port:, user:, password:, key:)
response = client.send_one(Message.build(:EMS_REQ_POWER_PV))
responses = client.send_many([...])
client.close
Constant Summary collapse
- AUTH_LEVELS =
{ 0 => :no_auth, 10 => :user, 20 => :installer, 30 => :service, 40 => :admin, 50 => :e3dc, 60 => :e3dc_root }.freeze
- DEFAULT_TIMEOUTS =
{ connect: 10.0, send: 10.0, receive: 10.0 }.freeze
Instance Attribute Summary collapse
-
#auth_level ⇒ Object
readonly
Returns the value of attribute auth_level.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #close ⇒ Object
- #connected? ⇒ Boolean
-
#initialize(host:, port: 5033, user:, password:, key:, timeouts: {}, use_checksum: true) ⇒ Client
constructor
A new instance of Client.
- #send_many(messages) ⇒ Object
- #send_one(message) ⇒ Object
Constructor Details
#initialize(host:, port: 5033, user:, password:, key:, timeouts: {}, use_checksum: true) ⇒ Client
Returns a new instance of Client.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/e3dc_mqtt/rscp/client.rb', line 37 def initialize(host:, port: 5033, user:, password:, key:, timeouts: {}, use_checksum: true) @host = host @port = port @user = user @password = password @key = Rijndael256.derive_key(key) @use_checksum = use_checksum @timeouts = DEFAULT_TIMEOUTS.merge(timeouts) @socket = nil @encryptor = nil @decryptor = nil @auth_level = nil end |
Instance Attribute Details
#auth_level ⇒ Object (readonly)
Returns the value of attribute auth_level.
35 36 37 |
# File 'lib/e3dc_mqtt/rscp/client.rb', line 35 def auth_level @auth_level end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
35 36 37 |
# File 'lib/e3dc_mqtt/rscp/client.rb', line 35 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
35 36 37 |
# File 'lib/e3dc_mqtt/rscp/client.rb', line 35 def port @port end |
Instance Method Details
#authenticated? ⇒ Boolean
55 56 57 |
# File 'lib/e3dc_mqtt/rscp/client.rb', line 55 def authenticated? !@auth_level.nil? && @auth_level != :no_auth end |
#close ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/e3dc_mqtt/rscp/client.rb', line 59 def close @socket&.close ensure @socket = nil @encryptor = nil @decryptor = nil @auth_level = nil end |
#connected? ⇒ Boolean
51 52 53 |
# File 'lib/e3dc_mqtt/rscp/client.rb', line 51 def connected? !@socket.nil? end |
#send_many(messages) ⇒ Object
72 73 74 75 76 |
# File 'lib/e3dc_mqtt/rscp/client.rb', line 72 def send_many() ensure_authenticated () end |
#send_one(message) ⇒ Object
68 69 70 |
# File 'lib/e3dc_mqtt/rscp/client.rb', line 68 def send_one() send_many([]).first end |