Skip to content

Commit

Permalink
fix(johnson control) send command headers (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioFavalliR authored Oct 3, 2023
1 parent 6e85750 commit b165b95
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
9 changes: 8 additions & 1 deletion drivers/johnson_controls/metasys.cr
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ class JohnsonControls::Metasys < PlaceOS::Driver
GetObjectAttributesWithSamplesResponse.from_json(response.body)
end

def get_single_object_presentValue(id : String) : GetSingleObjectPresentValueResponse
response = get_request("/objects/#{id}/attributes/presentValue")
raise "request failed with #{response.status_code}\n#{response.body}" unless response.success?

GetSingleObjectPresentValueResponse.from_json(response.body)
end

def get_samples_for_an_object_attribute(id : String, attribute_id : String, start_time : String, end_time : String, page : Int32 = 1, page_size : Int32 = 10) : GetSamplesForAnObjectAttributeResponse
response = get_request("/objects/#{id}/attributes/#{attribute_id}/samples",
start_time: start_time,
Expand Down Expand Up @@ -242,7 +249,7 @@ class JohnsonControls::Metasys < PlaceOS::Driver
end

private def put_request(path : String, body)
put(path, headers: {"Authorization" => get_token}, body: body.to_json)
put(path, headers: {"Authorization" => get_token , "Content-Type" => CONTENT_TYPE}, body: body.to_json)
end

@[Security(Level::Support)]
Expand Down
25 changes: 25 additions & 0 deletions drivers/johnson_controls/metasys_models.cr
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,31 @@ module JohnsonControls
property object_url : String
end

class GetSingleObjectPresentValueResponse
include JSON::Serializable

class Item
include JSON::Serializable

class Value
include JSON::Serializable

@[JSON::Field(key: "value")]
property value : String?

@[JSON::Field(key: "reliability")]
property reliability : String?

@[JSON::Field(key: "priority")]
property next : String?
end
@[JSON::Field(key: "presentValue")]
property presentValue : Value
end
@[JSON::Field(key: "item")]
property item : Item
end

class SamplesResponse
include JSON::Serializable

Expand Down

0 comments on commit b165b95

Please sign in to comment.