Class: MqttApiClient::Device
- Inherits:
-
Object
- Object
- MqttApiClient::Device
- Defined in:
- lib/mqtt_api_client/device.rb
Constant Summary collapse
- TIMEOUT_SECONDS =
2
Instance Attribute Summary collapse
-
#device_identifier ⇒ Object
readonly
Returns the value of attribute device_identifier.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#mqtt_client ⇒ Object
readonly
Returns the value of attribute mqtt_client.
Instance Method Summary collapse
- #disconnect ⇒ Object
- #file_list ⇒ Object
- #health_status ⇒ Object
-
#initialize(mqtt_client:, device_identifier:, logger: default_logger(device_identifier)) ⇒ Device
constructor
A new instance of Device.
Constructor Details
#initialize(mqtt_client:, device_identifier:, logger: default_logger(device_identifier)) ⇒ Device
Returns a new instance of Device.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mqtt_api_client/device.rb', line 14 def initialize(mqtt_client:, device_identifier:, logger: default_logger(device_identifier)) @mqtt_client = mqtt_client @device_identifier = device_identifier @logger = logger logger&.info "Command logger initialized at #{Time.now}" subscribe_to_all( "device/#{device_identifier}/file_list", "device/#{device_identifier}/health_status" ) end |
Instance Attribute Details
#device_identifier ⇒ Object (readonly)
Returns the value of attribute device_identifier.
9 10 11 |
# File 'lib/mqtt_api_client/device.rb', line 9 def device_identifier @device_identifier end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/mqtt_api_client/device.rb', line 9 def logger @logger end |
#mqtt_client ⇒ Object (readonly)
Returns the value of attribute mqtt_client.
9 10 11 |
# File 'lib/mqtt_api_client/device.rb', line 9 def mqtt_client @mqtt_client end |
Instance Method Details
#disconnect ⇒ Object
57 58 59 |
# File 'lib/mqtt_api_client/device.rb', line 57 def disconnect mqtt_client.disconnect end |
#file_list ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mqtt_api_client/device.rb', line 27 def file_list mqtt_client.publish("device/#{device_identifier}/command", "file_list") begin process_get( "device/#{device_identifier}/file_list", "file_list" ) rescue Timeout::Error => e logger&.error "file_list timeout: #{e}" Timeout::Error.new(e) end end |
#health_status ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mqtt_api_client/device.rb', line 42 def health_status mqtt_client.publish("device/#{device_identifier}/command", "health_status") begin process_get( "device/#{device_identifier}/health_status", "health_status" ) rescue Timeout::Error => e logger&.error "health_status timeout: #{e}" Timeout::Error.new(e) end end |