fritzbox-smarthome 0.2.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d754754bef500b80a9c564a254f1df9104e69ba518484a6e1cbecea64332e2b0
4
- data.tar.gz: 21b050b1a1e3fbb4810a3b7e6fea598eb877d08588073aa63af6043f75ca87ba
3
+ metadata.gz: b8e0195a6e63ff7455d046a2795abecb92cc7f90534f2e66780b7b55a36e867c
4
+ data.tar.gz: b3813af3a7b38b0fac17bb83bd24bea5d312cd7ab0db5c5adba39cb983599547
5
5
  SHA512:
6
- metadata.gz: c5df4e76d262a3d441e68c73abb48f5bda3ad3b588756f2344f1a8dd174e16ccaf98d4858d87beb45bebf96a99dca6e1a434c9c3b0db078b1474ff2264a81dba
7
- data.tar.gz: 13637177a564bead4b2a331fd18fd2ec90677b3aa117b4be69d3bcda6b5f9f574763b178c88e5bd2fe6e166d087380ca963c0df6b3aea3561ffec855980d4f2c
6
+ metadata.gz: 0ba494fb0ba09894f97696a94c471f486cec8bc820fe1c02467f2071fc384bb94df6864e0f4d85e399e7851e6123061c036093048b7cde96369aa02352d38e92
7
+ data.tar.gz: f58785489fab952caa6a37c10a32385f7eb14d55f1712ea034f2fced9e98b480840c6277642e264a76e902aae4166fd87c84e11deacff4165b342cd27b50ec4b
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.0.0
1
+ 3.1.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.5.0
4
+
5
+ * Unify on/off interface
6
+ * Provides `#active?` and `#toggle!` methods
7
+ * Adds new functionality to `Switch`
8
+ * Replacing own implementation in `Lightbulb`
9
+
10
+ ## v0.4.0
11
+
12
+ * Add support for Fritz!DECT lightbulbs
13
+
14
+ ## v0.3.0
15
+
16
+ * Use generic Actor class for unrecognised device
17
+ * Allow usage in rails up to 7.1.x
18
+ * Use ruby 3.1.x in development
19
+ * Update a other dependencies
20
+
3
21
  ## v0.2.0
4
22
 
5
23
  **Attention**: This release contains breaking changes! Check [README](README.md) for new interface.
data/README.md CHANGED
@@ -5,6 +5,7 @@ Ruby client library to interface with Smarthome features of your FritzBox.
5
5
  Currently implemented actor types:
6
6
 
7
7
  * Heater
8
+ * Lightbulb
8
9
  * SmokeDetector
9
10
  * Switch
10
11
 
@@ -38,7 +39,7 @@ end
38
39
  actors = Fritzbox::Smarthome::Actor.all
39
40
 
40
41
  # Get all actors of type Heater
41
- heaters = Fritzbox::Smarthome::Heaters.all
42
+ heaters = Fritzbox::Smarthome::Heater.all
42
43
  heaters.last.update_hkr_temp_set(BigDecimal('21.5'))
43
44
  ```
44
45
 
@@ -20,14 +20,14 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_dependency 'activesupport', '>= 5.1', '< 6.2'
24
- spec.add_dependency 'activemodel', '>= 5.1', '< 6.2'
25
- spec.add_dependency 'httparty', '~> 0.16'
23
+ spec.add_dependency 'activesupport', '>= 5.1', '<= 7.1'
24
+ spec.add_dependency 'activemodel', '>= 5.1', '<= 7.1'
25
+ spec.add_dependency 'httparty', '~> 0.20'
26
26
  spec.add_dependency 'nori', '~> 2.6'
27
- spec.add_dependency 'nokogiri', '~> 1.8'
27
+ spec.add_dependency 'nokogiri', '~> 1.13'
28
28
 
29
29
  spec.add_development_dependency 'rake', '~> 13.0'
30
- spec.add_development_dependency 'rspec', '~> 3.0'
31
- spec.add_development_dependency 'webmock', '~> 3.3'
32
- spec.add_development_dependency 'byebug', '~> 11.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.11'
31
+ spec.add_development_dependency 'webmock', '~> 3.14'
32
+ spec.add_development_dependency 'byebug', '~> 11.1'
33
33
  end
@@ -17,7 +17,7 @@ module Fritzbox
17
17
  response = get(command: 'getdevicelistinfos')
18
18
  xml = nori.parse(response.body)
19
19
  Array.wrap(types.map { |type| xml.dig('devicelist', type) }.flatten).compact.map do |data|
20
- klass = Actor.descendants.find { |k| k.match?(data) }
20
+ klass = Actor.descendants.find { |k| k.match?(data) } || Actor
21
21
  self.in?([klass, Actor]) ? klass.new_from_api(data) : nil
22
22
  end.compact
23
23
  end
@@ -28,8 +28,8 @@ module Fritzbox
28
28
  type: data.dig('groupinfo').present? ? :group : :device,
29
29
  ain: data.dig('@identifier').to_s,
30
30
  present: data.dig('present') == '1',
31
- name: data.dig('name').to_s,
32
- manufacturer: data.dig('manufacturer').to_s,
31
+ name: (data.dig('name') || data.dig('@productname')).to_s,
32
+ manufacturer: (data.dig('manufacturer') || data.dig('@manufacturer')).to_s,
33
33
  group_members: data.dig('groupinfo', 'members').to_s.split(',').presence
34
34
  )
35
35
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fritzbox
4
+ module Smarthome
5
+ class Lightbulb < Actor
6
+
7
+ include Properties::SimpleOnOff
8
+
9
+ class << self
10
+ def match?(data)
11
+ data.fetch('@productname', '') =~ /FRITZ!DECT 5\d{2}/i
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fritzbox
4
+ module Smarthome
5
+ class NullLogger < Logger
6
+ def initialize(*_args)
7
+ super(File::NULL)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fritzbox
4
+ module Smarthome
5
+ module Properties
6
+ # Defines a common interface/behaviour for actors with the "simpleonoff" state.
7
+ # The including class is expected to have an `ain` attribute defined.
8
+ module SimpleOnOff
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ attr_accessor :simpleonoff_state
13
+ end
14
+
15
+ module ClassMethods
16
+ def new_from_api(data)
17
+ instance = defined?(super) ? super : new
18
+ instance.simpleonoff_state = data.dig('simpleonoff', 'state').to_i
19
+ instance
20
+ end
21
+ end
22
+
23
+ # @return [Boolean]
24
+ def active?
25
+ simpleonoff_state.to_s == "1"
26
+ end
27
+
28
+ # Makes a request to the Fritzbox and set the current instance's active state.
29
+ #
30
+ # The instance state is kept in memory and not checked with the Fritzbox state. It is
31
+ # possible that the device is switched on/off through other means.
32
+ #
33
+ # @example
34
+ # lightbulb.active?
35
+ # # => true
36
+ # lightbulb.toggle!
37
+ # # => 0
38
+ # lightbulb.active?
39
+ # # => false
40
+ # @return [false, Integer] Returns the new on/off state or false when the request
41
+ # was unsuccessful
42
+ # @raise [ArgumentError] if the including class does not respond to `#ain`
43
+ def toggle!
44
+ raise ArgumentError, "Attribute `ain` is missing on #{inspect}" unless respond_to?(:ain)
45
+ value = active? ? 0 : 1
46
+ response =
47
+ Fritzbox::Smarthome::Resource.get(command: 'setsimpleonoff', ain: ain, onoff: value)
48
+
49
+ response.ok? && @simpleonoff_state = value
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fritzbox/smarthome/properties/simple_on_off'
4
+
5
+ module Fritzbox
6
+ module Smarthome
7
+ module Properties
8
+ end
9
+ end
10
+ end
@@ -2,11 +2,18 @@ module Fritzbox
2
2
  module Smarthome
3
3
  class Resource
4
4
  class << self
5
- def get(command:, ain: nil, param: nil)
5
+ # @param params [Hash] key/value pairs that will be appended to the switchcmd query string
6
+ def get(command:, ain: nil, param: nil, **params)
6
7
  url = "#{config.endpoint}/webservices/homeautoswitch.lua?switchcmd=#{command}&sid=#{authenticate}"
7
8
  url = "#{url}&ain=#{ain}" if ain.present?
8
9
  url = "#{url}&param=#{param}" if param.present?
9
10
 
11
+ params.each_with_object(url) do |(key, value)|
12
+ url = "#{url}&#{key}=#{value}"
13
+ end
14
+
15
+ config.logger.debug(url)
16
+
10
17
  HTTParty.get(url, **httparty_options)
11
18
  end
12
19
 
@@ -2,12 +2,13 @@ module Fritzbox
2
2
  module Smarthome
3
3
  class Switch < Actor
4
4
 
5
+ include Properties::SimpleOnOff
6
+
5
7
  attr_accessor \
6
8
  :switch_state,
7
9
  :switch_mode,
8
10
  :switch_lock,
9
11
  :switch_devicelock,
10
- :simpleonoff_state,
11
12
  :powermeter_voltage,
12
13
  :powermeter_power,
13
14
  :powermeter_energy,
@@ -26,7 +27,6 @@ module Fritzbox
26
27
  switch_mode: data.dig('switch', 'mode').to_s,
27
28
  switch_lock: data.dig('switch', 'lock').to_i,
28
29
  switch_devicelock: data.dig('switch', 'devicelock').to_i,
29
- simpleonoff_state: data.dig('simpleonoff', 'state').to_i,
30
30
  powermeter_voltage: data.dig('powermeter', 'voltage').to_i,
31
31
  powermeter_power: data.dig('powermeter', 'power').to_i,
32
32
  powermeter_energy: data.dig('powermeter', 'energy').to_i,
@@ -1,5 +1,5 @@
1
1
  module Fritzbox
2
2
  module Smarthome
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.5.0'.freeze
4
4
  end
5
5
  end
@@ -4,11 +4,14 @@ require 'httparty'
4
4
  require 'nori'
5
5
 
6
6
  require 'fritzbox/smarthome/version'
7
+ require 'fritzbox/smarthome/null_logger'
8
+ require 'fritzbox/smarthome/properties'
7
9
  require 'fritzbox/smarthome/resource'
8
10
  require 'fritzbox/smarthome/actor'
9
11
  require 'fritzbox/smarthome/heater'
10
12
  require 'fritzbox/smarthome/switch'
11
13
  require 'fritzbox/smarthome/smoke_detector'
14
+ require 'fritzbox/smarthome/lightbulb'
12
15
 
13
16
  module Fritzbox
14
17
  module Smarthome
@@ -28,7 +31,7 @@ module Fritzbox
28
31
  defaults.username = 'smarthome'
29
32
  defaults.password = 'verysmart'
30
33
  defaults.verify_ssl = true
31
- defaults.logger = nil
34
+ defaults.logger = NullLogger.new
32
35
  end
33
36
 
34
37
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fritzbox-smarthome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klaus Meyer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-04 00:00:00.000000000 Z
11
+ date: 2022-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -17,9 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.1'
20
- - - "<"
20
+ - - "<="
21
21
  - !ruby/object:Gem::Version
22
- version: '6.2'
22
+ version: '7.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +27,9 @@ dependencies:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '5.1'
30
- - - "<"
30
+ - - "<="
31
31
  - !ruby/object:Gem::Version
32
- version: '6.2'
32
+ version: '7.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activemodel
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -37,9 +37,9 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '5.1'
40
- - - "<"
40
+ - - "<="
41
41
  - !ruby/object:Gem::Version
42
- version: '6.2'
42
+ version: '7.1'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -47,23 +47,23 @@ dependencies:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '5.1'
50
- - - "<"
50
+ - - "<="
51
51
  - !ruby/object:Gem::Version
52
- version: '6.2'
52
+ version: '7.1'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: httparty
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '0.16'
59
+ version: '0.20'
60
60
  type: :runtime
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
- version: '0.16'
66
+ version: '0.20'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: nori
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -84,14 +84,14 @@ dependencies:
84
84
  requirements:
85
85
  - - "~>"
86
86
  - !ruby/object:Gem::Version
87
- version: '1.8'
87
+ version: '1.13'
88
88
  type: :runtime
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
- version: '1.8'
94
+ version: '1.13'
95
95
  - !ruby/object:Gem::Dependency
96
96
  name: rake
97
97
  requirement: !ruby/object:Gem::Requirement
@@ -112,42 +112,42 @@ dependencies:
112
112
  requirements:
113
113
  - - "~>"
114
114
  - !ruby/object:Gem::Version
115
- version: '3.0'
115
+ version: '3.11'
116
116
  type: :development
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: '3.0'
122
+ version: '3.11'
123
123
  - !ruby/object:Gem::Dependency
124
124
  name: webmock
125
125
  requirement: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: '3.3'
129
+ version: '3.14'
130
130
  type: :development
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - "~>"
135
135
  - !ruby/object:Gem::Version
136
- version: '3.3'
136
+ version: '3.14'
137
137
  - !ruby/object:Gem::Dependency
138
138
  name: byebug
139
139
  requirement: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - "~>"
142
142
  - !ruby/object:Gem::Version
143
- version: '11.0'
143
+ version: '11.1'
144
144
  type: :development
145
145
  prerelease: false
146
146
  version_requirements: !ruby/object:Gem::Requirement
147
147
  requirements:
148
148
  - - "~>"
149
149
  - !ruby/object:Gem::Version
150
- version: '11.0'
150
+ version: '11.1'
151
151
  description: ''
152
152
  email:
153
153
  - spam@klaus-meyer.net
@@ -171,6 +171,10 @@ files:
171
171
  - lib/fritzbox/smarthome.rb
172
172
  - lib/fritzbox/smarthome/actor.rb
173
173
  - lib/fritzbox/smarthome/heater.rb
174
+ - lib/fritzbox/smarthome/lightbulb.rb
175
+ - lib/fritzbox/smarthome/null_logger.rb
176
+ - lib/fritzbox/smarthome/properties.rb
177
+ - lib/fritzbox/smarthome/properties/simple_on_off.rb
174
178
  - lib/fritzbox/smarthome/resource.rb
175
179
  - lib/fritzbox/smarthome/smoke_detector.rb
176
180
  - lib/fritzbox/smarthome/switch.rb
@@ -179,7 +183,7 @@ homepage: https://github.com/klausmeyer/fritzbox-smarthome
179
183
  licenses:
180
184
  - MIT
181
185
  metadata: {}
182
- post_install_message:
186
+ post_install_message:
183
187
  rdoc_options: []
184
188
  require_paths:
185
189
  - lib
@@ -194,8 +198,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
198
  - !ruby/object:Gem::Version
195
199
  version: '0'
196
200
  requirements: []
197
- rubygems_version: 3.2.3
198
- signing_key:
201
+ rubygems_version: 3.3.7
202
+ signing_key:
199
203
  specification_version: 4
200
204
  summary: Client library to interface with Smarthome features of your FritzBox
201
205
  test_files: []