fritzbox-smarthome 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +10 -2
- data/lib/fritzbox/smarthome.rb +4 -1
- data/lib/fritzbox/smarthome/actor.rb +11 -29
- data/lib/fritzbox/smarthome/heater.rb +41 -0
- data/lib/fritzbox/smarthome/smoke_detector.rb +25 -0
- data/lib/fritzbox/smarthome/switch.rb +41 -0
- data/lib/fritzbox/smarthome/version.rb +1 -1
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d754754bef500b80a9c564a254f1df9104e69ba518484a6e1cbecea64332e2b0
|
4
|
+
data.tar.gz: 21b050b1a1e3fbb4810a3b7e6fea598eb877d08588073aa63af6043f75ca87ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5df4e76d262a3d441e68c73abb48f5bda3ad3b588756f2344f1a8dd174e16ccaf98d4858d87beb45bebf96a99dca6e1a434c9c3b0db078b1474ff2264a81dba
|
7
|
+
data.tar.gz: 13637177a564bead4b2a331fd18fd2ec90677b3aa117b4be69d3bcda6b5f9f574763b178c88e5bd2fe6e166d087380ca963c0df6b3aea3561ffec855980d4f2c
|
data/CHANGELOG.md
CHANGED
@@ -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
|
-
|
34
|
-
|
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
|
data/lib/fritzbox/smarthome.rb
CHANGED
@@ -4,8 +4,11 @@ require 'httparty'
|
|
4
4
|
require 'nori'
|
5
5
|
|
6
6
|
require 'fritzbox/smarthome/version'
|
7
|
-
require
|
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
|
-
:
|
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
|
-
|
25
|
-
|
26
|
-
|
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:
|
35
|
-
type:
|
36
|
-
ain:
|
37
|
-
present:
|
38
|
-
name:
|
39
|
-
|
40
|
-
|
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
|
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.
|
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-
|
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.
|
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: []
|