Coverage for fio_wrapper/endpoints/endpoints_v1/building.py: 100%
15 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-16 11:50 +0100
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-16 11:50 +0100
1"""Access building information from FIO.
2"""
3from typing import Optional
4from fio_wrapper.endpoints.abstracts.abstract_building import AbstractBuilding
5from fio_wrapper.endpoints.abstracts.abstract_endpoint import AbstractEndpoint
6from fio_wrapper.exceptions import BuildingTickerNotFound
7from fio_wrapper.models.building_models import BuildingTicker, BuildingTickerList
10class Building(AbstractBuilding, AbstractEndpoint):
11 # /building/{BuildingTicker}
12 def get(
13 self, building_ticker: str, timeout: Optional[float] = None
14 ) -> BuildingTicker:
15 """Gets a single building from FIO
17 Args:
18 building_ticker (str): Building Ticker (e.g., "CHP")
19 timeout (float, optional): Request timeout in seconds. Defaults to None.
21 Raises:
22 BuildingTickerNotFound: Building Ticker was not found
24 Returns:
25 BuildingTicker: Building
26 """
27 (status, data) = self.adapter.get(
28 endpoint=self.urls.building_get_url(building_ticker=building_ticker),
29 err_codes=[204],
30 timeout=timeout,
31 )
33 if status == 200:
34 return BuildingTicker.model_validate(data)
35 elif status == 204:
36 raise BuildingTickerNotFound("Buildingticker not found")
38 # /building/allbuildings
39 def all(self, timeout: Optional[float] = None) -> BuildingTickerList:
40 """Gets all buildings from FIO
42 Args:
43 timeout (float, optional): Request timeout in seconds. Defaults to None.
45 Returns:
46 BuildingTickerList: List of Buildings as List[BuildingTicker]
47 """
48 (_, data) = self.adapter.get(
49 endpoint=self.urls.building_get_all_url(), timeout=timeout
50 )
52 return BuildingTickerList.model_validate(data)