homewizard 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cf2be37844f8ebf7f1f75f5101f82880a7b42bd6459775205c8116a2a7f3e301
4
+ data.tar.gz: 9337540f203e196510e389e8fc92ef144793e944b02d64fdac2aac09758cf42c
5
+ SHA512:
6
+ metadata.gz: 9f9207c361c6af79b868518870fedba224b11553a05d5d2fa8ee14f3095c8ae47f99da34925805c296c56c02125649ddf5e568a0817d7d806847a84115c2df23
7
+ data.tar.gz: 4c171b7732cdd144cfa44ae2873d22c9dfb40fc3fa6e7dc839d2adc627dda164d07b4bab3246e5680e5323d8c6c1a7be56c195b0dda447343304b40a06ed8d40
data/.env.template ADDED
@@ -0,0 +1,2 @@
1
+ HOMEWIZARD_P1_API_HOST=http://192.1.2.3
2
+ HOMEWIZARD_ENERGY_METER=http://192.1.2.4
data/.gitignore ADDED
@@ -0,0 +1,45 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+ /data/
13
+ *.log
14
+ *.txt
15
+ *.json
16
+ *.yml
17
+ .DS_Store
18
+
19
+ # Used by dotenv library to load environment variables.
20
+ .env
21
+
22
+
23
+ ## Documentation cache and generated files:
24
+ /.yardoc/
25
+ /_yardoc/
26
+ /doc/
27
+ /rdoc/
28
+
29
+ ## Environment normalization:
30
+ /.bundle/
31
+ /vendor/bundle
32
+ /lib/bundler/man/
33
+
34
+ # for a library or gem, you might want to ignore these files since the code is
35
+ # intended to run in multiple environments; otherwise, check them in:
36
+ # Gemfile.lock
37
+ # .ruby-version
38
+ # .ruby-gemset
39
+
40
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
41
+ .rvmrc
42
+
43
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
44
+ # .rubocop-https?--*
45
+ Gemfile.lock
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-02-24
4
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in hudu.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # Hudu API
2
+ [![Version](https://img.shields.io/gem/v/homewizard.svg)](https://rubygems.org/gems/hudu)
3
+
4
+ This is a wrapper for the HomeWizard rest API.
5
+
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'homewizard'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install homewizard
22
+
23
+ ## Usage
24
+
25
+ Before you start making the requests to API provide the endpoint using the configuration wrapping.
26
+
27
+ ```ruby
28
+ require 'homewizard'
29
+ require 'logger'
30
+
31
+ # use do block
32
+ HomeWizard.configure do |config|
33
+ config.endpoint = ENV['HOMEWIZARD_P1_API_HOST'].downcase
34
+ end
35
+
36
+ # or configure with options hash
37
+ client = HomeWizard.client({ logger: Logger.new('debug.log) })
38
+
39
+ # check api version
40
+ return unless if client.device_info.api_version.eql? 'v1'
41
+
42
+ # get last data
43
+ data = client.recent_data
44
+
45
+ if data.active_power_w < 0
46
+ # do something to use energy
47
+
48
+ end
49
+ ```
50
+
51
+ ## Resources
52
+ Endpoint for data related requests
53
+
54
+ |Resource|API endpoint|
55
+ |:--|:--|
56
+ |.recent_data | /api/v1/data|
57
+ |.socket_state | /api/v1/state|
58
+ |.telegram | /api/v1/telegram|
59
+ |.identify | /api/v1/identify|
60
+
61
+ ## Publishing
62
+
63
+ 1. Update version in [version.rb](lib/homewizard/version.rb).
64
+ 2. Add release to [CHANGELOG.md](CHANGELOG.md)
65
+ 3. Commit.
66
+ 4. Test build.
67
+ ```
68
+ > rake build
69
+
70
+ ```
71
+ 5. Release
72
+ ```
73
+ > rake release
74
+
75
+ ## Contributing
76
+
77
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jancotanis/homewizard.
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'dotenv'
5
+ require 'rake/testtask'
6
+
7
+ Dotenv.load
8
+
9
+ #system './bin/cc-test-reporter before-build'
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'test'
12
+ t.libs << 'lib'
13
+ t.test_files = FileList['test/**/*_test.rb']
14
+ end
15
+
16
+ require 'rubocop/rake_task'
17
+ RuboCop::RakeTask.new
18
+ task default: %i[test rubocop]
19
+ #system './bin/cc-test-reporter after-build'
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/homewizard/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'homewizard'
7
+ s.version = HomeWizard::VERSION
8
+ s.authors = ['Janco Tanis']
9
+ s.email = 'gems@jancology.com'
10
+ s.license = 'MIT'
11
+
12
+ s.summary = 'A Ruby wrapper for the HomeWizard APIs (readonly)'
13
+ s.homepage = 'https://rubygems.org/gems/homewizard'
14
+
15
+ s.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
16
+
17
+ s.metadata['homepage_uri'] = s.homepage
18
+ s.metadata['source_code_uri'] = 'https://github.com/jancotanis/homewizard'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+ s.bindir = 'exe'
26
+ s.executables = s.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ s.require_paths = ['lib']
28
+
29
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
30
+ s.platform = Gem::Platform::RUBY
31
+ s.add_runtime_dependency 'faraday'
32
+ s.add_runtime_dependency 'wrapi', ">= 0.3.0"
33
+ s.add_development_dependency 'dotenv'
34
+ s.add_development_dependency 'minitest'
35
+ s.add_development_dependency 'simplecov'
36
+ s.add_development_dependency 'rubocop'
37
+ end
@@ -0,0 +1,34 @@
1
+ require "wrapi"
2
+ #require File.expand_path('authentication', __dir__)
3
+ #require File.expand_path('configuration', __dir__)
4
+
5
+ module HomeWizard
6
+ # @private
7
+ class API
8
+
9
+ # @private
10
+ attr_accessor *WrAPI::Configuration::VALID_OPTIONS_KEYS
11
+
12
+ # Creates a new API and copies settings from singleton
13
+ def initialize(options = {})
14
+ options = HomeWizard.options.merge(options)
15
+ WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
16
+ send("#{key}=", options[key])
17
+ end
18
+ end
19
+
20
+ def config
21
+ conf = {}
22
+ WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
23
+ conf[key] = send key
24
+ end
25
+ conf
26
+ end
27
+
28
+ # include Configuration
29
+ include WrAPI::Connection
30
+ include WrAPI::Request
31
+ # include WrAPI::Authentication
32
+ # include Authentication
33
+ end
34
+ end
@@ -0,0 +1,56 @@
1
+ require File.expand_path('api', __dir__)
2
+ require File.expand_path('error', __dir__)
3
+
4
+ module HomeWizard
5
+ # Wrapper for the HomeWizard REST API
6
+ #
7
+ # @see https://api-documentation.homewizard.com/docs/introduction/
8
+ class Client < API
9
+ attr_reader :device_info
10
+ # get client to access P1 meter
11
+ # @return [P1Client]
12
+ def initialize(options = {})
13
+ # create client and copy access_token and set default headers
14
+ super(options)
15
+ @device_info = product_info
16
+ puts "* probably incompatible api version" unless 'v1'.eql? product_info.api_version
17
+ rescue Faraday::ForbiddenError => e
18
+ raise APInotEnabledError.new e.response[:body]['error']
19
+ end
20
+ # return api path
21
+ def self.url(method)
22
+ path = method ? "v1/#{method}" : ''
23
+ "/api/#{path}"
24
+ end
25
+
26
+
27
+ private
28
+ def self.api_endpoint(method, path = nil, valid_devices = nil)
29
+
30
+ _url = self.url(path)
31
+ # all records
32
+ self.send(:define_method, method) do |params = {}|
33
+ if valid_devices && !valid_devices.include?(@device_info.product_type)
34
+ raise DeviceTypeError.new "Method #{method} not available for this device #{@device_info.product_name}"
35
+ end
36
+ r = get(_url, params)
37
+ end
38
+ end
39
+
40
+ public
41
+ # return device information
42
+ # product_type
43
+ # product_name
44
+ # serial
45
+ # firmware_version
46
+ # api_version
47
+ # devices: HWE-P1, HWE-SKT, HWE-WTR, HWE-KWH1 and SDM230-wifi, HWE-KWH3 and SDM630-wifi
48
+ api_endpoint :product_info
49
+ # devices: HWE-P1, HWE-SKT, HWE-WTR, HWE-KWH1 and SDM230-wifi, HWE-KWH3 and SDM630-wifi
50
+ api_endpoint :recent_measurement, 'data', ['HWE-P1', 'HWE-SKT']
51
+ api_endpoint :socket_state, 'state', ['HWE-SKT']
52
+ api_endpoint :telegram, 'telegram', ['HWE-P1']
53
+ api_endpoint :identify, 'identify', ['HWE-P1', 'HWE-SKT']
54
+
55
+ end
56
+ end
@@ -0,0 +1,11 @@
1
+ module HomeWizard
2
+
3
+ # Generic error to be able to rescue all Hudu errors
4
+ class HomeWizardError < StandardError; end
5
+
6
+ # Wrong api for given device
7
+ class APInotEnabledError < HomeWizardError; end
8
+
9
+ # Wrong api for given device
10
+ class DeviceTypeError < HomeWizardError; end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HomeWizard
4
+ VERSION = '0.1.0'
5
+ end
data/lib/homewizard.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "wrapi"
2
+ require File.expand_path('homewizard/client', __dir__)
3
+
4
+ module HomeWizard
5
+ extend WrAPI::Configuration
6
+ extend WrAPI::RespondTo
7
+
8
+ DEFAULT_UA = 'Ruby HomeWizard API client'
9
+ #
10
+ # @return [Hudu::Client]
11
+ def self.client(options = {})
12
+ HomeWizard::Client.new({ user_agent: DEFAULT_UA }.merge(options))
13
+ end
14
+
15
+ def self.reset
16
+ super
17
+ self.endpoint = nil
18
+ self.user_agent = DEFAULT_UA
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: homewizard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Janco Tanis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: wrapi
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: dotenv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email: gems@jancology.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".env.template"
104
+ - ".gitignore"
105
+ - CHANGELOG.md
106
+ - Gemfile
107
+ - README.md
108
+ - Rakefile
109
+ - homewizard.gemspec
110
+ - lib/homewizard.rb
111
+ - lib/homewizard/api.rb
112
+ - lib/homewizard/client.rb
113
+ - lib/homewizard/error.rb
114
+ - lib/homewizard/version.rb
115
+ homepage: https://rubygems.org/gems/homewizard
116
+ licenses:
117
+ - MIT
118
+ metadata:
119
+ homepage_uri: https://rubygems.org/gems/homewizard
120
+ source_code_uri: https://github.com/jancotanis/homewizard
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 2.4.0
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubygems_version: 3.2.12
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: A Ruby wrapper for the HomeWizard APIs (readonly)
140
+ test_files: []