fritzbox-smarthome 0.1.3 → 0.2.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: 782cdee20c938c01c4ee6f6560e05f7a7636d8b9315e6c63f577959e3df85f45
4
- data.tar.gz: a33ea016b04d0a710d13e0e1089850d74f1d16f14e9346683fac961640be2851
3
+ metadata.gz: d754754bef500b80a9c564a254f1df9104e69ba518484a6e1cbecea64332e2b0
4
+ data.tar.gz: 21b050b1a1e3fbb4810a3b7e6fea598eb877d08588073aa63af6043f75ca87ba
5
5
  SHA512:
6
- metadata.gz: af9c5ed89753c194f8eefaf29dcf4893e9f68c99e7595cb95196b778b9bdbce2a7a6e2efa0b650ddf52f5fccab2e19f0bd065be68a4d805f1f94b96990a6fd61
7
- data.tar.gz: 4aabacf20397befaf87d069307e2bc525bfaee04ecae6563d63ee4b1c6487f62ede5f75d850257e63fecf87ade33c21b7ef85877a00de4fde861b763b0fb7137
6
+ metadata.gz: c5df4e76d262a3d441e68c73abb48f5bda3ad3b588756f2344f1a8dd174e16ccaf98d4858d87beb45bebf96a99dca6e1a434c9c3b0db078b1474ff2264a81dba
7
+ data.tar.gz: 13637177a564bead4b2a331fd18fd2ec90677b3aa117b4be69d3bcda6b5f9f574763b178c88e5bd2fe6e166d087380ca963c0df6b3aea3561ffec855980d4f2c
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.2.0
4
+
5
+ **Attention**: This release contains breaking changes! Check [README](README.md) for new interface.
6
+
7
+ * Add support for more actors types: switches and smoke detector
8
+ * Extract heater specific attributes and logic to own class
9
+
3
10
  ## v0.1.3
4
11
 
5
12
  * avoid nil error in actors:all smart devices request
data/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  Ruby client library to interface with Smarthome features of your FritzBox.
4
4
 
5
+ Currently implemented actor types:
6
+
7
+ * Heater
8
+ * SmokeDetector
9
+ * Switch
10
+
5
11
  ## Installation
6
12
 
7
13
  Add this line to your application's Gemfile:
@@ -28,10 +34,12 @@ Fritzbox::Smarthome.configure do |config|
28
34
  config.verify_ssl = false
29
35
  end
30
36
 
37
+ # Get all actors of any type
31
38
  actors = Fritzbox::Smarthome::Actor.all
32
39
 
33
- actor = actors.last
34
- actor.update_hkr_temp_set(BigDecimal.new('21.5'))
40
+ # Get all actors of type Heater
41
+ heaters = Fritzbox::Smarthome::Heaters.all
42
+ heaters.last.update_hkr_temp_set(BigDecimal('21.5'))
35
43
  ```
36
44
 
37
45
  ## Development
@@ -4,8 +4,11 @@ require 'httparty'
4
4
  require 'nori'
5
5
 
6
6
  require 'fritzbox/smarthome/version'
7
- require "fritzbox/smarthome/resource"
7
+ require 'fritzbox/smarthome/resource'
8
8
  require 'fritzbox/smarthome/actor'
9
+ require 'fritzbox/smarthome/heater'
10
+ require 'fritzbox/smarthome/switch'
11
+ require 'fritzbox/smarthome/smoke_detector'
9
12
 
10
13
  module Fritzbox
11
14
  module Smarthome
@@ -9,49 +9,31 @@ module Fritzbox
9
9
  :ain,
10
10
  :present,
11
11
  :name,
12
- :hkr_temp_is,
13
- :hkr_temp_set,
14
- :hkr_next_change_period,
15
- :hkr_next_change_temp,
12
+ :manufacturer,
16
13
  :group_members
17
14
 
18
15
  class << self
19
16
  def all(types: ['group', 'device'])
20
17
  response = get(command: 'getdevicelistinfos')
21
18
  xml = nori.parse(response.body)
22
-
23
19
  Array.wrap(types.map { |type| xml.dig('devicelist', type) }.flatten).compact.map do |data|
24
- new_from_api(data)
25
- end
26
- end
27
-
28
- def only_heaters
29
- all.select { |record| record.hkr_temp_is.present? }
20
+ klass = Actor.descendants.find { |k| k.match?(data) }
21
+ self.in?([klass, Actor]) ? klass.new_from_api(data) : nil
22
+ end.compact
30
23
  end
31
24
 
32
25
  def new_from_api(data)
33
26
  new(
34
- id: data.dig('@id').to_s,
35
- type: data.dig('groupinfo').present? ? :group : :device,
36
- ain: data.dig('@identifier').to_s,
37
- present: data.dig('present') == '1',
38
- name: data.dig('name').to_s,
39
- hkr_temp_is: data.dig('hkr', 'tist').to_i * 0.5,
40
- hkr_temp_set: data.dig('hkr', 'tsoll').to_i * 0.5,
41
- hkr_next_change_period: Time.at(data.dig('hkr', 'nextchange', 'endperiod').to_i),
42
- hkr_next_change_temp: data.dig('hkr', 'nextchange', 'tchange').to_i * 0.5,
43
- group_members: data.dig('groupinfo', 'members').to_s.split(',').presence
27
+ id: data.dig('@id').to_s,
28
+ type: data.dig('groupinfo').present? ? :group : :device,
29
+ ain: data.dig('@identifier').to_s,
30
+ present: data.dig('present') == '1',
31
+ name: data.dig('name').to_s,
32
+ manufacturer: data.dig('manufacturer').to_s,
33
+ group_members: data.dig('groupinfo', 'members').to_s.split(',').presence
44
34
  )
45
35
  end
46
36
  end
47
-
48
- def update_hkr_temp_set(value)
49
- raise ArgumentError unless value.is_a? BigDecimal
50
- value = (value / 0.5).to_i
51
- response = self.class.get(command: 'sethkrtsoll', ain: ain, param: value)
52
- raise 'Could not set temperature' unless response.body == "#{value}\n"
53
- true
54
- end
55
37
  end
56
38
  end
57
39
  end
@@ -0,0 +1,41 @@
1
+ module Fritzbox
2
+ module Smarthome
3
+ class Heater < Actor
4
+
5
+ attr_accessor \
6
+ :battery,
7
+ :batterylow,
8
+ :hkr_temp_is,
9
+ :hkr_temp_set,
10
+ :hkr_next_change_period,
11
+ :hkr_next_change_temp
12
+
13
+ class << self
14
+ def match?(data)
15
+ data.key?('hkr')
16
+ end
17
+
18
+ def new_from_api(data)
19
+ instance = super
20
+ instance.assign_attributes(
21
+ battery: data.dig('battery').to_i,
22
+ batterylow: data.dig('batterylow').to_i,
23
+ hkr_temp_is: data.dig('hkr', 'tist').to_i * 0.5,
24
+ hkr_temp_set: data.dig('hkr', 'tsoll').to_i * 0.5,
25
+ hkr_next_change_period: Time.at(data.dig('hkr', 'nextchange', 'endperiod').to_i),
26
+ hkr_next_change_temp: data.dig('hkr', 'nextchange', 'tchange').to_i * 0.5
27
+ )
28
+ instance
29
+ end
30
+ end
31
+
32
+ def update_hkr_temp_set(value)
33
+ raise ArgumentError unless value.is_a? BigDecimal
34
+ value = (value / 0.5).to_i
35
+ response = self.class.get(command: 'sethkrtsoll', ain: ain, param: value)
36
+ raise 'Could not set temperature' unless response.body == "#{value}\n"
37
+ true
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,25 @@
1
+ module Fritzbox
2
+ module Smarthome
3
+ class SmokeDetector < Actor
4
+
5
+ attr_accessor \
6
+ :alert_state,
7
+ :last_alert
8
+
9
+ class << self
10
+ def match?(data)
11
+ data.key?('alert')
12
+ end
13
+
14
+ def new_from_api(data)
15
+ instance = super
16
+ instance.assign_attributes(
17
+ alert_state: data.dig('alert', 'state').to_i,
18
+ last_alert: Time.at(data.dig('alert', 'lastalertchgtimestamp').to_i)
19
+ )
20
+ instance
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ module Fritzbox
2
+ module Smarthome
3
+ class Switch < Actor
4
+
5
+ attr_accessor \
6
+ :switch_state,
7
+ :switch_mode,
8
+ :switch_lock,
9
+ :switch_devicelock,
10
+ :simpleonoff_state,
11
+ :powermeter_voltage,
12
+ :powermeter_power,
13
+ :powermeter_energy,
14
+ :temperature_celsius,
15
+ :temperature_offset
16
+
17
+ class << self
18
+ def match?(data)
19
+ data.key?('switch')
20
+ end
21
+
22
+ def new_from_api(data)
23
+ instance = super
24
+ instance.assign_attributes(
25
+ switch_state: data.dig('switch', 'state').to_i,
26
+ switch_mode: data.dig('switch', 'mode').to_s,
27
+ switch_lock: data.dig('switch', 'lock').to_i,
28
+ switch_devicelock: data.dig('switch', 'devicelock').to_i,
29
+ simpleonoff_state: data.dig('simpleonoff', 'state').to_i,
30
+ powermeter_voltage: data.dig('powermeter', 'voltage').to_i,
31
+ powermeter_power: data.dig('powermeter', 'power').to_i,
32
+ powermeter_energy: data.dig('powermeter', 'energy').to_i,
33
+ temperature_celsius: data.dig('temperature', 'celsius').to_i,
34
+ temperature_offset: data.dig('temperature', 'offset').to_i
35
+ )
36
+ instance
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  module Fritzbox
2
2
  module Smarthome
3
- VERSION = '0.1.3'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
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.1.3
4
+ version: 0.2.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-01 00:00:00.000000000 Z
11
+ date: 2021-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -170,13 +170,16 @@ files:
170
170
  - fritzbox-smarthome.gemspec
171
171
  - lib/fritzbox/smarthome.rb
172
172
  - lib/fritzbox/smarthome/actor.rb
173
+ - lib/fritzbox/smarthome/heater.rb
173
174
  - lib/fritzbox/smarthome/resource.rb
175
+ - lib/fritzbox/smarthome/smoke_detector.rb
176
+ - lib/fritzbox/smarthome/switch.rb
174
177
  - lib/fritzbox/smarthome/version.rb
175
178
  homepage: https://github.com/klausmeyer/fritzbox-smarthome
176
179
  licenses:
177
180
  - MIT
178
181
  metadata: {}
179
- post_install_message:
182
+ post_install_message:
180
183
  rdoc_options: []
181
184
  require_paths:
182
185
  - lib
@@ -191,8 +194,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
194
  - !ruby/object:Gem::Version
192
195
  version: '0'
193
196
  requirements: []
194
- rubygems_version: 3.1.2
195
- signing_key:
197
+ rubygems_version: 3.2.3
198
+ signing_key:
196
199
  specification_version: 4
197
200
  summary: Client library to interface with Smarthome features of your FritzBox
198
201
  test_files: []