fritzbox-smarthome 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +1 -0
- data/lib/fritzbox/smarthome/lightbulb.rb +1 -21
- data/lib/fritzbox/smarthome/properties/simple_on_off.rb +54 -0
- data/lib/fritzbox/smarthome/properties.rb +10 -0
- data/lib/fritzbox/smarthome/switch.rb +2 -2
- data/lib/fritzbox/smarthome/version.rb +1 -1
- data/lib/fritzbox/smarthome.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8e0195a6e63ff7455d046a2795abecb92cc7f90534f2e66780b7b55a36e867c
|
4
|
+
data.tar.gz: b3813af3a7b38b0fac17bb83bd24bea5d312cd7ab0db5c5adba39cb983599547
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ba494fb0ba09894f97696a94c471f486cec8bc820fe1c02467f2071fc384bb94df6864e0f4d85e399e7851e6123061c036093048b7cde96369aa02352d38e92
|
7
|
+
data.tar.gz: f58785489fab952caa6a37c10a32385f7eb14d55f1712ea034f2fced9e98b480840c6277642e264a76e902aae4166fd87c84e11deacff4165b342cd27b50ec4b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,32 +4,12 @@ module Fritzbox
|
|
4
4
|
module Smarthome
|
5
5
|
class Lightbulb < Actor
|
6
6
|
|
7
|
-
|
8
|
-
:simpleonoff_state
|
7
|
+
include Properties::SimpleOnOff
|
9
8
|
|
10
9
|
class << self
|
11
10
|
def match?(data)
|
12
11
|
data.fetch('@productname', '') =~ /FRITZ!DECT 5\d{2}/i
|
13
12
|
end
|
14
|
-
|
15
|
-
def new_from_api(data)
|
16
|
-
instance = super
|
17
|
-
instance.assign_attributes(
|
18
|
-
simpleonoff_state: data.dig('simpleonoff', 'state').to_i,
|
19
|
-
)
|
20
|
-
instance
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def active?
|
25
|
-
simpleonoff_state == 1
|
26
|
-
end
|
27
|
-
|
28
|
-
def toggle!
|
29
|
-
value = active? ? 0 : 1
|
30
|
-
response = self.class.get(command: 'setsimpleonoff', ain: ain, onoff: value)
|
31
|
-
|
32
|
-
response.ok? && @simpleonoff_state = value
|
33
13
|
end
|
34
14
|
end
|
35
15
|
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
|
@@ -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,
|
data/lib/fritzbox/smarthome.rb
CHANGED
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Klaus Meyer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -173,6 +173,8 @@ files:
|
|
173
173
|
- lib/fritzbox/smarthome/heater.rb
|
174
174
|
- lib/fritzbox/smarthome/lightbulb.rb
|
175
175
|
- lib/fritzbox/smarthome/null_logger.rb
|
176
|
+
- lib/fritzbox/smarthome/properties.rb
|
177
|
+
- lib/fritzbox/smarthome/properties/simple_on_off.rb
|
176
178
|
- lib/fritzbox/smarthome/resource.rb
|
177
179
|
- lib/fritzbox/smarthome/smoke_detector.rb
|
178
180
|
- lib/fritzbox/smarthome/switch.rb
|