basic entity get/show

This commit is contained in:
2023-01-13 21:47:31 +02:00
parent 26ea76c8e9
commit 38f51a5de6
13 changed files with 74 additions and 38 deletions

View File

@ -1,7 +1,25 @@
class Entity < ApplicationRecord
validate :name , presence: true
validate :ha_id , presence: true
validate :type , presence: true
validate :member_id , presence: true
belongs_to :member
validates :name , presence: true
validates :ha_id , presence: true
validates :ha_type , presence: true
validates :member_id , presence: true
def value
@data = Entity.response("/" + ha_id)
@data["state"]
end
def self.ha_entities
res = response()
res.collect{|i| i["entity_id"]}.select{|i| i.include?("4a") || i.include?("2d")}
end
def self.response(path = "")
token = Rails.application.credentials[:ha_token]
all = RestClient.get( "10.30.39.238:8123/api/states#{path}" ,
{"Authorization" => "Bearer #{token}" })
JSON.parse(all.body)
end
end

View File

@ -6,6 +6,8 @@ class Member < ApplicationRecord
mount_uploader :picture, PictureUploader
has_many :entity
def admin
true
end