basic integration of entities to profile

This commit is contained in:
2023-01-13 22:23:23 +02:00
parent 38f51a5de6
commit d869eab476
6 changed files with 24 additions and 17 deletions

View File

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

View File

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