hass-client 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 424e5b5945d9b3664fcd367db46bf2afe2f8473e4fa225cd0ee6824e7c2f0e76
4
- data.tar.gz: 8b3191a2e3aaf64f253c0f957a01003a8258ac83bcae04320d31d58887d51d6c
3
+ metadata.gz: 37eb66063f66121647a2b626e3d05fd3eb2510e366b567b0efe0cd090229294f
4
+ data.tar.gz: b4527ad41c79ebc1772eb0d4f3daa434d0e44a4e23d91b607e6ed0e586fee7cc
5
5
  SHA512:
6
- metadata.gz: 8d8480e5f51bdc57622714871afca209e35943305e32015f7411b1d6305191ac3e1579065f534fda3c484142bc577d71ef6d5b6b4b505f86f778808514d74808
7
- data.tar.gz: 8ea81f919350830449e0d4b6b4e71188cef3dde701f3a17730df3c777abcb2410123db9100917298b22faef273b8c8f8a928666c39d3a60dc399bf244c3dc09f
6
+ metadata.gz: f7cb29f7185d7f362c5fec706d5bc4c3d6d7912ede1998e99ee25596201ae774c1451525de2686161a458899f0283bedab7fbe8725e63afd1ef6ba73d0a58800
7
+ data.tar.gz: b89ed9be9b25dfdf5914d69a1277913f7af5b56b69c8498cfc0f607023308a05de76da364cf72419ebc681a28ddf92e1b392e90d34ead038f08fc518a66a0721
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/README.md CHANGED
@@ -1,19 +1,21 @@
1
- # hass, Ruby client for HomeAssistant
1
+ # hass-client, Ruby client for HomeAssistant
2
2
 
3
- hass is a simple Ruby client for the HomeAssistant API.
3
+ hass-client is a simple Ruby client for the HomeAssistant API.
4
+
5
+ The idea was to have a client which has actual classes for the available devices. This way, you can inspect objects and see your possible actions. It works for the available services but not yet for all states.
4
6
 
5
7
  ## Installation
6
8
 
7
9
  Install the gem via
8
10
 
9
11
  ```bash
10
- gem install hass
12
+ gem install hass-client
11
13
  ```
12
14
 
13
15
  or put it in your Gemfile
14
16
 
15
17
  ```ruby
16
- gem 'hass'
18
+ gem 'hass-client'
17
19
  ```
18
20
 
19
21
  ## Usage
@@ -60,3 +62,29 @@ client = Hass::Client.new('localhost', 8123, 'api_token')
60
62
  light = client.light('light.living_room')
61
63
  light.toggle
62
64
  ```
65
+
66
+ You can get a list of your available device types (domains) via
67
+
68
+ ```ruby
69
+ pp(client.domains.map { |domain| domain['domain'] })
70
+ ```
71
+
72
+ You can also get a list of your available entity ids via
73
+
74
+ ```ruby
75
+ pp(client.states.map {|state| state['entity_id']} )
76
+ ```
77
+
78
+ After initializing the client, you can instantiate the available classes directly. You need to provide the client object to be able to use them:
79
+
80
+ ```ruby
81
+ client = Hass::Client.new('localhost', 8123, 'api_token')
82
+ mediaplayer = Hass::MediaPlayer.new('media_player.yamaha_receiver')
83
+ mediaplayer.client = client
84
+ pp mediaplayer.attributes
85
+ mediaplayer.select_source(source: 'HDMI1')
86
+ ```
87
+
88
+ ## Caveats
89
+
90
+ To make multiple calls to client.domains faster, the result is cached. If you have a longer running application, you will have to set @domains to nil to re-request the data. Other requests are not cached at all and this might significantly slow down access to multiple devices.
data/hass-ruby.gemspec CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'hass-client'
6
- spec.version = '0.1.0'
6
+ spec.version = '0.2.0'
7
7
  spec.authors = ['Gerrit Visscher']
8
8
  spec.email = ['gerrit@visscher.de']
9
9
  spec.summary = 'A small library to access Home Assistant.'
data/lib/hass/client.rb CHANGED
@@ -66,6 +66,10 @@ module Hass
66
66
  @domains ||= get('/services')
67
67
  end
68
68
 
69
+ def states
70
+ get('/states')
71
+ end
72
+
69
73
  def snake_to_camel(text)
70
74
  text.split('_').collect(&:capitalize).join
71
75
  end
data/lib/hass/domain.rb CHANGED
@@ -40,6 +40,18 @@ module Hass
40
40
  check_params(service, params)
41
41
  end
42
42
 
43
+ def state_data
44
+ @client.get("/states/#{@entity_id}")
45
+ end
46
+
47
+ def attributes
48
+ state_data['attributes']
49
+ end
50
+
51
+ def state
52
+ state_data['state']
53
+ end
54
+
43
55
  def data
44
56
  self.class.const_get('DATA')
45
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hass-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerrit Visscher
@@ -33,6 +33,7 @@ executables:
33
33
  extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
+ - ".gitignore"
36
37
  - Gemfile
37
38
  - README.md
38
39
  - bin/hass-send