2727 Asset ,
2828 AssetDatapoint ,
2929 AssetDatapointPeriod ,
30- DatapointsRequestBody ,
30+ AssetDatapointQuery ,
3131)
3232
3333
@@ -56,6 +56,8 @@ class OpenRemoteClient:
5656 service_user: The service user for the OpenRemote API.
5757 service_user_secret: The service user secret for the OpenRemote API.
5858
59+ Raises:
60+ Exception: If the authentication fails
5961 """
6062
6163 logger = logging .getLogger (__name__ )
@@ -121,6 +123,7 @@ def health_check(self) -> bool:
121123 Returns:
122124 bool: True if healthy, False if not.
123125 """
126+
124127 url = f"{ self .openremote_url } /api/master/health"
125128
126129 request = self .__build_request ("GET" , url )
@@ -142,6 +145,7 @@ def retrieve_assets(self, realm: str) -> list[Asset] | None:
142145 Returns:
143146 list[Asset] | None: List of assets or None
144147 """
148+
145149 url = f"{ self .openremote_url } /api/master/asset/query"
146150 asset_query = {"recursive" : True , "realm" : {"name" : realm }}
147151
@@ -167,6 +171,7 @@ def retrieve_asset_datapoint_period(self, asset_id: str, attribute_name: str) ->
167171 Returns:
168172 AssetDatapointPeriod | None: The datapoints timestamp period of the asset attribute
169173 """
174+
170175 query = f"?assetId={ asset_id } &attributeName={ attribute_name } "
171176 url = f"{ self .openremote_url } /api/master/asset/datapoint/periods{ query } "
172177
@@ -176,30 +181,34 @@ def retrieve_asset_datapoint_period(self, asset_id: str, attribute_name: str) ->
176181 try :
177182 response = client .send (request )
178183 response .raise_for_status ()
179- datapoint_period = AssetDatapointPeriod (** response .json ())
180- return datapoint_period
184+ return AssetDatapointPeriod (** response .json ())
181185 except (httpx .HTTPStatusError , httpx .ConnectError ) as e :
182186 self .logger .error (f"Error retrieving asset datapoint period: { e } " )
183187 return None
184188
185189 def retrieve_historical_datapoints (
186- self , asset_id : str , attribute_name : str , from_timestamp : int , to_timestamp : int
190+ self ,
191+ asset_id : str ,
192+ attribute_name : str ,
193+ from_timestamp : int ,
194+ to_timestamp : int ,
187195 ) -> list [AssetDatapoint ] | None :
188196 """Retrieve the historical data points of a given asset attribute.
189197
190198 Args:
191199 asset_id: The ID of the asset.
192200 attribute_name: The name of the attribute.
193- from_timestamp: The start timestamp.
194- to_timestamp: The end timestamp.
201+ from_timestamp: Epoch timestamp in milliseconds .
202+ to_timestamp: Epoch timestamp in milliseconds .
195203
196204 Returns:
197205 list[AssetDatapoint] | None: List of historical data points or None
198206 """
207+
199208 params = f"{ asset_id } /{ attribute_name } "
200209 url = f"{ self .openremote_url } /api/master/asset/datapoint/{ params } "
201210
202- request_body = DatapointsRequestBody (
211+ request_body = AssetDatapointQuery (
203212 fromTimestamp = from_timestamp ,
204213 toTimestamp = to_timestamp ,
205214 )
@@ -227,6 +236,7 @@ def write_predicted_datapoints(self, asset_id: str, attribute_name: str, datapoi
227236 Returns:
228237 bool: True if successful
229238 """
239+
230240 params = f"{ asset_id } /{ attribute_name } "
231241 url = f"{ self .openremote_url } /api/master/asset/predicted/{ params } "
232242
@@ -244,23 +254,28 @@ def write_predicted_datapoints(self, asset_id: str, attribute_name: str, datapoi
244254 return False
245255
246256 def retrieve_predicted_datapoints (
247- self , asset_id : str , attribute_name : str , from_timestamp : int , to_timestamp : int
257+ self ,
258+ asset_id : str ,
259+ attribute_name : str ,
260+ from_timestamp : int ,
261+ to_timestamp : int ,
248262 ) -> list [AssetDatapoint ] | None :
249263 """Retrieve the predicted data points of a given asset attribute.
250264
251265 Args:
252266 asset_id: The ID of the asset.
253267 attribute_name: The name of the attribute.
254- from_timestamp: The start timestamp.
255- to_timestamp: The end timestamp.
268+ from_timestamp: Epoch timestamp in milliseconds .
269+ to_timestamp: Epoch timestamp in milliseconds .
256270
257271 Returns:
258272 list[AssetDatapoint] | None: List of predicted data points or None
259273 """
274+
260275 params = f"{ asset_id } /{ attribute_name } "
261276 url = f"{ self .openremote_url } /api/master/asset/predicted/{ params } "
262277
263- request_body = DatapointsRequestBody (
278+ request_body = AssetDatapointQuery (
264279 fromTimestamp = from_timestamp ,
265280 toTimestamp = to_timestamp ,
266281 )
0 commit comments