huginn_myq_agent 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 92fcd2a20ad0d54481544fe5317f9172be615ac9e0b3c09a9cd657683752e6c4
4
+ data.tar.gz: 74719d1fb59cd2878f74e0e81662854969a327eb37c796d115ab1cb09043002d
5
+ SHA512:
6
+ metadata.gz: 933711a76fcb23a914253b67da900d98658dba1a8997a254d979f91a2da84601130b715e55257e9b5519f064837797e09c953880f1881e83b6eb158e31da0e54
7
+ data.tar.gz: 5fbe07e9e2eaae6e1c8ec6527785eac2b68b1e12464b291a36c33d646da354ec600db125470c78a1ad1aa7b0bbf49799e6cca83593d7504344f654e3fe115c6a
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2020 Jesse Gillies
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,102 @@
1
+ require 'ruby_myq'
2
+
3
+ module Agents
4
+ class MyqAgent < Agent
5
+ include FormConfigurable
6
+ cannot_receive_events!
7
+ default_schedule '12h'
8
+
9
+ description <<-MD
10
+ Add a Agent description here
11
+ MD
12
+
13
+ def default_options
14
+ {
15
+ 'email_address' => '',
16
+ 'password' => '',
17
+ 'door_name' => '',
18
+ 'action' => ''
19
+ }
20
+ end
21
+
22
+ form_configurable :email_address, type: :text
23
+ form_configurable :password, type: :text
24
+ form_configurable :door_name, type: :text
25
+ form_configurable :action, type: :array, values: ['status', 'open', 'close', 'toggle']
26
+
27
+ def validate_options
28
+ if options['email_address'].blank?
29
+ errors.add(:base, 'email address is required')
30
+ end
31
+ if options['password'].blank?
32
+ errors.add(:base, 'password is required')
33
+ end
34
+ if options['door_name'].blank?
35
+ errors.add(:base, 'door_name is required')
36
+ end
37
+ if options['action'].blank?
38
+ errors.add(:base, 'action is required')
39
+ end
40
+ end
41
+
42
+ def working?
43
+ # Implement me! Maybe one of these next two lines would be a good fit?
44
+ received_event_without_error?
45
+ end
46
+
47
+ def check
48
+ door = select_door(interpolated['door_name'])
49
+ if interpolated['action'] == 'status'
50
+ create_event :payload => status(door)
51
+ elsif interpolated['action'] == 'open'
52
+ open_door(door)
53
+ create_event :payload => status(door)
54
+ elsif interpolated['action'] == 'close'
55
+ close(door)
56
+ create_event :payload => status(door)
57
+ end
58
+ end
59
+
60
+ def create_system
61
+ system = RubyMyq::System.new(interpolated['email_address'],interpolated['password'])
62
+ end
63
+
64
+ def select_door(door_name)
65
+ system = create_system()
66
+ door = system.find_door_by_name(door_name)
67
+ end
68
+
69
+ def status(door_name)
70
+ door = select_door(door_name)
71
+ status = {
72
+ 'state' => door.status,
73
+ 'since' => door.status_since
74
+ }
75
+ return status
76
+ end
77
+
78
+ def close_door(door_name)
79
+ door = select_door(door_name)
80
+ door.close
81
+ end
82
+
83
+ def open_door(door_name)
84
+ door = select_door(door_name)
85
+ door.open
86
+ end
87
+
88
+ def toggle_door(door_name)
89
+ door = select_door(door_name)
90
+ if door.status == "open"
91
+ door.close
92
+ elsif door.status == "closed"
93
+ door.open
94
+ end
95
+ end
96
+
97
+
98
+
99
+ # def receive(incoming_events)
100
+ # end
101
+ end
102
+ end
@@ -0,0 +1,4 @@
1
+ require 'huginn_agent'
2
+
3
+ #HuginnAgent.load 'huginn_myq_agent/concerns/my_agent_concern'
4
+ HuginnAgent.register 'huginn_myq_agent/myq_agent'
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+ require 'huginn_agent/spec_helper'
3
+
4
+ describe Agents::MyqAgent do
5
+ before(:each) do
6
+ @valid_options = Agents::MyqAgent.new.default_options
7
+ @checker = Agents::MyqAgent.new(:name => "MyqAgent", :options => @valid_options)
8
+ @checker.user = users(:bob)
9
+ @checker.save!
10
+ end
11
+
12
+ pending "add specs here"
13
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: huginn_myq_agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jesse Gillies
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: huginn_agent
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: ruby_myq
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.1
69
+ description: Write a longer description or delete this line.
70
+ email:
71
+ - jessegillies@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - LICENSE.txt
77
+ - lib/huginn_myq_agent.rb
78
+ - lib/huginn_myq_agent/myq_agent.rb
79
+ - spec/myq_agent_spec.rb
80
+ homepage: https://github.com/jgillies/huginn_myq_agent
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.0.3
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Write a short summary, because Rubygems requires one.
103
+ test_files:
104
+ - spec/myq_agent_spec.rb