fritzbox-smarthome 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37cd022a30a2468d0e2fd1c21ef92435eb43327791d5b946fcf5cde3d3dfeab3
4
- data.tar.gz: 21e8a2ff7d347b99e8c865caaa594f56de3356fcd5d0c73dbea65eebb8d8d05b
3
+ metadata.gz: 430136a0736fded1a9e2cf308cdeb00129e94514259915306146fc65be4fb04a
4
+ data.tar.gz: 8755e3f921c2c815b1e6d38d3372bcfff068e6a8aa7a47785d07213585e67101
5
5
  SHA512:
6
- metadata.gz: 9ae9f2ae8acc810dd26d9f6a0ee4c3372a3ce3bd38db87c13145bd7f5aeedfb384f8df6e5a6109ef7ca57f0cc9bc2521dcac01460b67fa90b268f90ff14246bb
7
- data.tar.gz: e2dcc816dd0110f36ce60cfe26ea4a1183b2f8358d8ccf459be84ac3ae2501d8fd7c7f321f750926ba3dd8afec063b95c0f06324a9340d81182959ff14314812
6
+ metadata.gz: 94ac858e01f25649f9171df8cf685658b4a4e17f5c230a1394569c37d3052444ed1b155d8eb9a58d61fc056eb471347ee5c0c163b0a777651a8abceac4a3c76a
7
+ data.tar.gz: 198756b6e8a1d7d2cfcf886e26f5e2efd3d75eb655d2533e94074c936b42da531d58147ceba13e3a54b5e621f66fe99f56fe5652cbdd6c2b64294a095fa5e22e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.4.0
4
+
5
+ * Add support for Fritz!DECT lightbulbs
6
+
3
7
  ## v0.3.0
4
8
 
5
9
  * Use generic Actor class for unrecognised device
@@ -29,7 +29,7 @@ module Fritzbox
29
29
  ain: data.dig('@identifier').to_s,
30
30
  present: data.dig('present') == '1',
31
31
  name: (data.dig('name') || data.dig('@productname')).to_s,
32
- manufacturer: data.dig('manufacturer').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,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fritzbox
4
+ module Smarthome
5
+ class Lightbulb < Actor
6
+
7
+ attr_accessor \
8
+ :simpleonoff_state
9
+
10
+ class << self
11
+ def match?(data)
12
+ data.fetch('@productname', '') =~ /FRITZ!DECT 5\d{2}/i
13
+ 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
+ end
34
+ end
35
+ end
36
+ 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
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  module Fritzbox
2
2
  module Smarthome
3
- VERSION = '0.3.0'.freeze
3
+ VERSION = '0.4.0'.freeze
4
4
  end
5
5
  end
@@ -4,11 +4,13 @@ require 'httparty'
4
4
  require 'nori'
5
5
 
6
6
  require 'fritzbox/smarthome/version'
7
+ require 'fritzbox/smarthome/null_logger'
7
8
  require 'fritzbox/smarthome/resource'
8
9
  require 'fritzbox/smarthome/actor'
9
10
  require 'fritzbox/smarthome/heater'
10
11
  require 'fritzbox/smarthome/switch'
11
12
  require 'fritzbox/smarthome/smoke_detector'
13
+ require 'fritzbox/smarthome/lightbulb'
12
14
 
13
15
  module Fritzbox
14
16
  module Smarthome
@@ -28,7 +30,7 @@ module Fritzbox
28
30
  defaults.username = 'smarthome'
29
31
  defaults.password = 'verysmart'
30
32
  defaults.verify_ssl = true
31
- defaults.logger = nil
33
+ defaults.logger = NullLogger.new
32
34
  end
33
35
 
34
36
  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.3.0
4
+ version: 0.4.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-04-25 00:00:00.000000000 Z
11
+ date: 2022-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -171,6 +171,8 @@ 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
174
176
  - lib/fritzbox/smarthome/resource.rb
175
177
  - lib/fritzbox/smarthome/smoke_detector.rb
176
178
  - lib/fritzbox/smarthome/switch.rb