lex-home-assistant 0.1.1

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: 68331129548615e43589c6732fab0cd1adfe97d26b4d983fd3d128482903eda4
4
+ data.tar.gz: 20f26f308a212f7c9c77862c86a25c4f817d62c278b84636d6c843aab73aec85
5
+ SHA512:
6
+ metadata.gz: 44cad4e6d372be29fd2b1324775a91fd51a237cb7eec42884d27e49a159f403a6fb85bf22fa39247fcbdd991ab0587a62487f799ae1486bf4ea03bf9fab608ad
7
+ data.tar.gz: 20da903e8a3e096e5811330dc313d62ba01b09c72093c73f55d45e35610d055fa6f77712038c1deb2d4b59fdb6f3826487799ab50c61cc3f4077c4e548169e4c
@@ -0,0 +1,16 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [origin]
5
+ pull_request:
6
+
7
+ jobs:
8
+ ci:
9
+ uses: LegionIO/.github/.github/workflows/ci.yml@main
10
+
11
+ release:
12
+ needs: ci
13
+ if: github.event_name == 'push' && github.ref == 'refs/heads/origin'
14
+ uses: LegionIO/.github/.github/workflows/release.yml@main
15
+ secrets:
16
+ rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,53 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.4
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Layout/LineLength:
7
+ Max: 160
8
+
9
+ Layout/SpaceAroundEqualsInParameterDefault:
10
+ EnforcedStyle: space
11
+
12
+ Layout/HashAlignment:
13
+ EnforcedHashRocketStyle: table
14
+ EnforcedColonStyle: table
15
+
16
+ Metrics/MethodLength:
17
+ Max: 50
18
+
19
+ Metrics/ClassLength:
20
+ Max: 1500
21
+
22
+ Metrics/ModuleLength:
23
+ Max: 1500
24
+
25
+ Metrics/BlockLength:
26
+ Max: 40
27
+ Exclude:
28
+ - 'spec/**/*'
29
+
30
+ Metrics/ParameterLists:
31
+ Max: 10
32
+
33
+ Metrics/AbcSize:
34
+ Max: 60
35
+
36
+ Metrics/CyclomaticComplexity:
37
+ Max: 15
38
+
39
+ Metrics/PerceivedComplexity:
40
+ Max: 17
41
+
42
+ Style/Documentation:
43
+ Enabled: false
44
+
45
+ Style/SymbolArray:
46
+ Enabled: true
47
+
48
+ Style/FrozenStringLiteralComment:
49
+ Enabled: true
50
+ EnforcedStyle: always
51
+
52
+ Naming/FileName:
53
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2026-03-21
4
+
5
+ ### Added
6
+ - Initial release
7
+ - `Helpers::Client` — Faraday connection builder targeting Home Assistant REST API with Bearer token auth
8
+ - `Runners::Entities` — list_entities, get_entity
9
+ - `Runners::Services` — list_services, call_service
10
+ - `Runners::States` — get_state, set_state
11
+ - Standalone `Client` class for use outside the Legion framework
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'rake', '~> 12.0'
8
+ gem 'rspec', '~> 3.0'
9
+ gem 'rspec_junit_formatter'
10
+ gem 'rubocop'
11
+ gem 'rubocop-rspec'
12
+ gem 'webmock'
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # lex-home-assistant
2
+
3
+ LegionIO extension for Home Assistant integration via the Home Assistant REST API.
4
+
5
+ ## Installation
6
+
7
+ Add to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lex-home-assistant'
11
+ ```
12
+
13
+ ## Standalone Usage
14
+
15
+ ```ruby
16
+ require 'legion/extensions/home_assistant'
17
+
18
+ client = Legion::Extensions::HomeAssistant::Client.new(
19
+ url: 'http://homeassistant.local:8123/api',
20
+ token: 'your-long-lived-access-token'
21
+ )
22
+
23
+ # Entities
24
+ client.list_entities
25
+ client.get_entity(entity_id: 'light.living_room')
26
+
27
+ # Services
28
+ client.list_services
29
+ client.call_service(domain: 'light', service: 'turn_on', entity_id: 'light.living_room')
30
+ client.call_service(domain: 'light', service: 'turn_on', entity_id: 'light.living_room', data: { brightness: 200 })
31
+
32
+ # States
33
+ client.get_state(entity_id: 'sensor.temperature')
34
+ client.set_state(entity_id: 'sensor.temperature', state: '21.5', attributes: { unit_of_measurement: '°C' })
35
+ ```
36
+
37
+ ## Authentication
38
+
39
+ Home Assistant requires a long-lived access token passed as a Bearer token in the `Authorization` header. Generate a token from your Home Assistant profile page under Long-Lived Access Tokens.
40
+
41
+ ## License
42
+
43
+ MIT
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/legion/extensions/home_assistant/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lex-home-assistant'
7
+ spec.version = Legion::Extensions::HomeAssistant::VERSION
8
+ spec.authors = ['Esity']
9
+ spec.email = ['matthewdiverson@gmail.com']
10
+
11
+ spec.summary = 'LEX::HomeAssistant'
12
+ spec.description = 'Used to connect Legion to Home Assistant'
13
+ spec.homepage = 'https://github.com/LegionIO/lex-home-assistant'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.4'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-home-assistant'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-home-assistant/blob/main/CHANGELOG.md'
20
+ spec.metadata['rubygems_mfa_required'] = 'true'
21
+
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_dependency 'faraday', '~> 2.0'
30
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helpers/client'
4
+ require_relative 'runners/entities'
5
+ require_relative 'runners/services'
6
+ require_relative 'runners/states'
7
+
8
+ module Legion
9
+ module Extensions
10
+ module HomeAssistant
11
+ class Client
12
+ include Helpers::Client
13
+ include Runners::Entities
14
+ include Runners::Services
15
+ include Runners::States
16
+
17
+ attr_reader :opts
18
+
19
+ def initialize(url: 'http://homeassistant.local:8123/api', token: nil, **extra)
20
+ @opts = { url: url, token: token, **extra }
21
+ end
22
+
23
+ def settings
24
+ { options: @opts }
25
+ end
26
+
27
+ def connection(**override)
28
+ super(**@opts, **override)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module HomeAssistant
8
+ module Helpers
9
+ module Client
10
+ def connection(url: 'http://homeassistant.local:8123/api', token: nil, **_opts)
11
+ Faraday.new(url: url) do |conn|
12
+ conn.request :json
13
+ conn.response :json, content_type: /\bjson$/
14
+ conn.headers['Authorization'] = "Bearer #{token}" if token
15
+ conn.adapter Faraday.default_adapter
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module HomeAssistant
6
+ module Runners
7
+ module Entities
8
+ def list_entities(**)
9
+ resp = connection(**).get('/api/states')
10
+ { entities: resp.body }
11
+ end
12
+
13
+ def get_entity(entity_id:, **)
14
+ resp = connection(**).get("/api/states/#{entity_id}")
15
+ { entity: resp.body }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module HomeAssistant
6
+ module Runners
7
+ module Services
8
+ def list_services(**)
9
+ resp = connection(**).get('/api/services')
10
+ { services: resp.body }
11
+ end
12
+
13
+ def call_service(domain:, service:, entity_id: nil, data: {}, **)
14
+ payload = data.dup
15
+ payload[:entity_id] = entity_id if entity_id
16
+ resp = connection(**).post("/api/services/#{domain}/#{service}", payload)
17
+ { result: resp.body }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module HomeAssistant
6
+ module Runners
7
+ module States
8
+ def get_state(entity_id:, **)
9
+ resp = connection(**).get("/api/states/#{entity_id}")
10
+ { state: resp.body }
11
+ end
12
+
13
+ def set_state(entity_id:, state:, attributes: {}, **)
14
+ payload = { state: state, attributes: attributes }
15
+ resp = connection(**).post("/api/states/#{entity_id}", payload)
16
+ { state: resp.body }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module HomeAssistant
6
+ VERSION = '0.1.1'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/home_assistant/version'
4
+ require 'legion/extensions/home_assistant/helpers/client'
5
+ require 'legion/extensions/home_assistant/runners/entities'
6
+ require 'legion/extensions/home_assistant/runners/services'
7
+ require 'legion/extensions/home_assistant/runners/states'
8
+ require 'legion/extensions/home_assistant/client'
9
+
10
+ module Legion
11
+ module Extensions
12
+ module HomeAssistant
13
+ extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lex-home-assistant
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Esity
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ description: Used to connect Legion to Home Assistant
27
+ email:
28
+ - matthewdiverson@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".github/workflows/ci.yml"
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - CHANGELOG.md
38
+ - Gemfile
39
+ - README.md
40
+ - lex-home-assistant.gemspec
41
+ - lib/legion/extensions/home_assistant.rb
42
+ - lib/legion/extensions/home_assistant/client.rb
43
+ - lib/legion/extensions/home_assistant/helpers/client.rb
44
+ - lib/legion/extensions/home_assistant/runners/entities.rb
45
+ - lib/legion/extensions/home_assistant/runners/services.rb
46
+ - lib/legion/extensions/home_assistant/runners/states.rb
47
+ - lib/legion/extensions/home_assistant/version.rb
48
+ homepage: https://github.com/LegionIO/lex-home-assistant
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/LegionIO/lex-home-assistant
53
+ source_code_uri: https://github.com/LegionIO/lex-home-assistant
54
+ changelog_uri: https://github.com/LegionIO/lex-home-assistant/blob/main/CHANGELOG.md
55
+ rubygems_mfa_required: 'true'
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '3.4'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.6.9
71
+ specification_version: 4
72
+ summary: LEX::HomeAssistant
73
+ test_files: []