From 689b81ca2c35762ca598ec7bcebc82de84bcb6c9 Mon Sep 17 00:00:00 2001 From: Ali Naqvi Date: Fri, 29 May 2026 10:11:24 +0800 Subject: [PATCH 1/2] feat: [PPT-2505] added space_config field to control system model --- ...260529093000001_alter_sys_add_space_config.sql | 9 +++++++++ spec/control_system_spec.cr | 15 +++++++++++++++ src/placeos-models/control_system.cr | 2 ++ 3 files changed, 26 insertions(+) create mode 100644 migration/db/migrations/20260529093000001_alter_sys_add_space_config.sql diff --git a/migration/db/migrations/20260529093000001_alter_sys_add_space_config.sql b/migration/db/migrations/20260529093000001_alter_sys_add_space_config.sql new file mode 100644 index 00000000..0f62cea5 --- /dev/null +++ b/migration/db/migrations/20260529093000001_alter_sys_add_space_config.sql @@ -0,0 +1,9 @@ +-- +micrate Up +-- SQL in section 'Up' is executed when this migration is applied + +ALTER TABLE "sys" ADD COLUMN IF NOT EXISTS space_config JSONB NOT NULL DEFAULT '{}'::jsonb; + +-- +micrate Down +-- SQL section 'Down' is executed when this migration is rolled back + +ALTER TABLE "sys" DROP COLUMN IF EXISTS space_config; \ No newline at end of file diff --git a/spec/control_system_spec.cr b/spec/control_system_spec.cr index 3c7f7aae..ea35bd45 100644 --- a/spec/control_system_spec.cr +++ b/spec/control_system_spec.cr @@ -115,6 +115,21 @@ module PlaceOS::Model ids = data.map { |d| JSON.parse(d).as_h["id"].to_s } ids.sort.should eq zone_ids.sort end + + it "#space_config" do + cs = Generator.control_system.save! + cs.space_config["enabled"] = false + cs.space_config["allow_recurrence_bookings"] = "disabled" + cs.space_config["threshold"] = 0.25 + cs.space_config["temp"] = 50 + cs.space_config["i64"] = 20_i64 + cs.space_config["none"] = nil + cs.save + + cs.space_config["enabled"].should be_false + cs.space_config["allow_recurrence_bookings"].should eq("disabled") + cs.space_config["threshold"].should eq 0.25 + end end describe "validation" do diff --git a/src/placeos-models/control_system.cr b/src/placeos-models/control_system.cr index e8cf0b88..f4b8ce1c 100644 --- a/src/placeos-models/control_system.cr +++ b/src/placeos-models/control_system.cr @@ -73,6 +73,8 @@ module PlaceOS::Model attribute signage_last_seen : Time = -> { 5.hours.ago }, converter: PlaceOS::Model::Timestamps::EpochConverter, type: "integer", format: "Int64", mass_assignment: false belongs_to Playlist::Item, foreign_key: "playlist_item_id" + attribute space_config : Hash(String, String | Int32 | Int64 | Float64 | Bool | Nil) = {} of String => (String | Int32 | Int64 | Float64 | Bool | Nil) + def update_last_seen_time(item_id : String? = nil) system_id = self.id.as(String) From 6f1b3a4d3cf9e54b5ba7da5988a97e44072ab89a Mon Sep 17 00:00:00 2001 From: Ali Naqvi Date: Mon, 20 Jul 2026 10:48:30 +0800 Subject: [PATCH 2/2] refactor: make space_config json any hash --- spec/control_system_spec.cr | 14 ++++++++------ src/placeos-models/control_system.cr | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/spec/control_system_spec.cr b/spec/control_system_spec.cr index ea35bd45..c9563eff 100644 --- a/spec/control_system_spec.cr +++ b/spec/control_system_spec.cr @@ -118,12 +118,14 @@ module PlaceOS::Model it "#space_config" do cs = Generator.control_system.save! - cs.space_config["enabled"] = false - cs.space_config["allow_recurrence_bookings"] = "disabled" - cs.space_config["threshold"] = 0.25 - cs.space_config["temp"] = 50 - cs.space_config["i64"] = 20_i64 - cs.space_config["none"] = nil + space_config = {} of String => (String | Int32 | Int64 | Float64 | Bool | Nil) + space_config["enabled"] = false + space_config["allow_recurrence_bookings"] = "disabled" + space_config["threshold"] = 0.25 + space_config["temp"] = 50 + space_config["i64"] = 20_i64 + space_config["none"] = nil + cs.space_config = JSON.parse(space_config.to_json).as_h cs.save cs.space_config["enabled"].should be_false diff --git a/src/placeos-models/control_system.cr b/src/placeos-models/control_system.cr index f4b8ce1c..2f770aa1 100644 --- a/src/placeos-models/control_system.cr +++ b/src/placeos-models/control_system.cr @@ -73,7 +73,7 @@ module PlaceOS::Model attribute signage_last_seen : Time = -> { 5.hours.ago }, converter: PlaceOS::Model::Timestamps::EpochConverter, type: "integer", format: "Int64", mass_assignment: false belongs_to Playlist::Item, foreign_key: "playlist_item_id" - attribute space_config : Hash(String, String | Int32 | Int64 | Float64 | Bool | Nil) = {} of String => (String | Int32 | Int64 | Float64 | Bool | Nil) + attribute space_config : Hash(String, JSON::Any) = {} of String => JSON::Any def update_last_seen_time(item_id : String? = nil) system_id = self.id.as(String)