Class: Wizrb::Shared::Products::Device
- Inherits:
-
Object
- Object
- Wizrb::Shared::Products::Device
show all
- Defined in:
- lib/wizrb/shared/products/device.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(ip:, port: 38_899, state: Wizrb::Shared::State.new) ⇒ Device
Returns a new instance of Device.
19
20
21
22
23
24
|
# File 'lib/wizrb/shared/products/device.rb', line 19
def initialize(ip:, port: 38_899, state: Wizrb::Shared::State.new)
@ip = ip
@port = port
@state = state
connect
end
|
Instance Attribute Details
#ip ⇒ Object
Returns the value of attribute ip.
17
18
19
|
# File 'lib/wizrb/shared/products/device.rb', line 17
def ip
@ip
end
|
#port ⇒ Object
Returns the value of attribute port.
17
18
19
|
# File 'lib/wizrb/shared/products/device.rb', line 17
def port
@port
end
|
#state ⇒ Object
Returns the value of attribute state.
17
18
19
|
# File 'lib/wizrb/shared/products/device.rb', line 17
def state
@state
end
|
Instance Method Details
#dispatch_event(event) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/wizrb/shared/products/device.rb', line 72
def dispatch_event(event)
unless event.is_a?(Wizrb::Shared::Events::Base)
raise ArgumentError, "Not an instance of Wizrb::Shared::Events::Base"
end
dispatch(event)
end
|
#dispatch_events(*events) ⇒ Object
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/wizrb/shared/products/device.rb', line 80
def dispatch_events(*events)
events.each do |event|
unless event.is_a?(Wizrb::Shared::Events::Base)
raise ArgumentError, "Not an instance of Wizrb::Shared::Events::Base"
end
end
params = events.reduce({}) { |h, e| h.merge(e.params) }
dispatch_event(Wizrb::Shared::Events::Base.new(method: "setState", params: params))
end
|
#model_config ⇒ Object
30
31
32
|
# File 'lib/wizrb/shared/products/device.rb', line 30
def model_config
@model_config ||= dispatch({method: "getModelConfig", params: {}})&.dig("result")
end
|
#module_name ⇒ Object
38
39
40
|
# File 'lib/wizrb/shared/products/device.rb', line 38
def module_name
@module_name ||= system_config&.dig("moduleName")
end
|
#power_switch ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/wizrb/shared/products/device.rb', line 50
def power_switch
if refresh.state.power
power_off
else
power_on
end
end
|
#refresh ⇒ Object
66
67
68
69
70
|
# File 'lib/wizrb/shared/products/device.rb', line 66
def refresh
response = dispatch_event(Wizrb::Shared::Events::RefreshEvent.new)
state.parse!(response)
self
end
|
#system_config ⇒ Object
26
27
28
|
# File 'lib/wizrb/shared/products/device.rb', line 26
def system_config
@system_config ||= dispatch({method: "getSystemConfig", params: {}})&.dig("result")
end
|
#user_config ⇒ Object
34
35
36
|
# File 'lib/wizrb/shared/products/device.rb', line 34
def user_config
@user_config ||= dispatch({method: "getUserConfig", params: {}})&.dig("result")
end
|