@@ -47,6 +47,7 @@ defmodule BACnet.Protocol.ObjectTypes.Device do
4747 alias BACnet.Protocol.Device.ServicesSupported
4848 alias BACnet.Protocol.ObjectIdentifier
4949 alias BACnet.Protocol.ObjectsMacro
50+ alias BACnet.Protocol.ObjectsUtility.Internal
5051 alias BACnet.Protocol.Recipient
5152
5253 require Constants
@@ -164,33 +165,14 @@ defmodule BACnet.Protocol.ObjectTypes.Device do
164165 # Properties for when the device is capable of tracking date and time
165166 field ( :local_date , BACnetDate . t ( ) ,
166167 readonly: true ,
167- init_fun: & BACnetDate . utc_today / 0 ,
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- ]
168+ init_fun: & Internal . init_fun_local_date / 0 ,
169+ annotation: [ on_read_function: & update_local_date / 1 ]
180170 )
181171
182172 field ( :local_time , BACnetTime . t ( ) ,
183173 readonly: true ,
184- init_fun: & BACnetTime . utc_now / 0 ,
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- ]
174+ init_fun: & Internal . init_fun_local_time / 0 ,
175+ annotation: [ on_read_function: & update_local_time / 1 ]
194176 )
195177
196178 # Properties for COV reporting service
@@ -344,6 +326,29 @@ defmodule BACnet.Protocol.ObjectTypes.Device do
344326
345327 defp map_vendor_to_name ( _id ) , do: ""
346328
329+ @ spec update_local_date ( t ( ) ) :: { :ok , t ( ) } | { :error , term ( ) }
330+ defp update_local_date ( % __MODULE__ { } = obj ) do
331+ # Maybe we want to use DateTime.now/1 with the correct TimeZone? (the configured default)
332+ # We use DateTime instead of Date so when shifting the time, we get the correct date
333+ update_property (
334+ obj ,
335+ :local_date ,
336+ BACnetDate . from_date (
337+ DateTime . to_date ( DateTime . add ( DateTime . utc_now ( ) , - ( obj [ :utc_offset ] || 0 ) , :minute ) )
338+ )
339+ )
340+ end
341+
342+ @ spec update_local_time ( t ( ) ) :: { :ok , t ( ) } | { :error , term ( ) }
343+ defp update_local_time ( % __MODULE__ { } = obj ) do
344+ # Maybe we want to use DateTime.now/1 with the correct TimeZone? (the configured default)
345+ update_property (
346+ obj ,
347+ :local_time ,
348+ BACnetTime . from_time ( Time . add ( Time . utc_now ( ) , - ( obj [ :utc_offset ] || 0 ) , :minute ) )
349+ )
350+ end
351+
347352 @ spec inhibit_object_check ( t ( ) ) :: { :ok , t ( ) }
348353 defp inhibit_object_check ( obj ) do
349354 # Only patch vendor name if empty
0 commit comments