Skip to content

Commit 11fd9af

Browse files
author
CI
committed
Sync to GitHub
1 parent d10c702 commit 11fd9af

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

lib/bacnet/protocol/object_types/device.ex

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ defmodule BACnet.Protocol.ObjectTypes.Device do
1414
- `active_cov_subscriptions`
1515
- `apdu_timeout` (propagation on write)
1616
- `auto_slave_discovery`
17+
- `daylight_savings_status` (auto update on DST and propagation to UTC_Offset)
1718
- `device_address_binding`
1819
- `manual_slave_address_binding`
1920
- `max_info_frames` (marked as "readonly" and "default" value should be `1`)
@@ -62,6 +63,9 @@ defmodule BACnet.Protocol.ObjectTypes.Device do
6263
@typedoc """
6364
Represents a Device object. All keys should be treated as read-only,
6465
all updates should go only through `update_property/3`.
66+
67+
UTC Offset is positive for western hemisphere and negative for eastern hemisphere in minutes,
68+
i.e. UTC+2 is -120.
6569
"""
6670
bac_object Constants.macro_assert_name(:object_type, :device) do
6771
services(intrinsic: false)
@@ -161,13 +165,32 @@ defmodule BACnet.Protocol.ObjectTypes.Device do
161165
field(:local_date, BACnetDate.t(),
162166
readonly: true,
163167
init_fun: &BACnetDate.utc_today/0,
164-
annotation: [on_read_function: &update_property(&1, :local_date, BACnetDate.utc_today())]
168+
annotation: [
169+
# Maybe we want to use DateTime.now/1 with the correct TimeZone? (the configured default)
170+
# We use DateTime instead of Date so when shifting the time, we get the correct date
171+
on_read_function:
172+
&update_property(
173+
&1,
174+
:local_date,
175+
BACnetDate.from_date(
176+
DateTime.to_date(DateTime.add(DateTime.utc_now(), -(&1[:utc_offset] || 0), :minute))
177+
)
178+
)
179+
]
165180
)
166181

167182
field(:local_time, BACnetTime.t(),
168183
readonly: true,
169184
init_fun: &BACnetTime.utc_now/0,
170-
annotation: [on_read_function: &update_property(&1, :local_time, BACnetTime.utc_now())]
185+
annotation: [
186+
# Maybe we want to use DateTime.now/1 with the correct TimeZone? (the configured default)
187+
on_read_function:
188+
&update_property(
189+
&1,
190+
:local_time,
191+
BACnetTime.from_time(Time.add(Time.utc_now(), -(&1[:utc_offset] || 0), :minute))
192+
)
193+
]
171194
)
172195

173196
# Properties for COV reporting service

0 commit comments

Comments
 (0)