preheat_open.interfaces.Adapter

class preheat_open.interfaces.Adapter(building_model)

Bases: ABC

Abstract base class for building management system adapters.

An Adapter provides a standardized interface for accessing different building management systems. It handles connections, data retrieval, and system-specific operations while presenting a unified API.

Variables:

building_model – Configuration defining the types used by this adapter

Note

All concrete adapters must implement the abstract methods defined here. The adapter automatically logs method calls for methods starting with “get_”, “put_”, or “load_”.

Example:
>>> # Abstract class cannot be instantiated directly
>>> try:
...     adapter = Adapter()
... except TypeError as e:
...     "Can't instantiate abstract class" in str(e)
True
__init__(building_model)

Methods

__init__(building_model)

close()

Close connection to the building management system.

get_all_locations_collection()

Retrieve a collection containing all available locations.

get_all_locations_information()

Retrieve information about all available locations.

get_comfort_profile_setpoints(date_range, ...)

Retrieve comfort profile setpoints for a location and date range.

get_devices(location_id)

Retrieve all devices for a specific location.

get_electricity_prices(date_range, unit, ...)

Retrieve electricity prices for a unit and date range.

get_features(location_id)

Retrieve available features for a specific location.

get_location(location_id)

Retrieve a specific location by ID.

get_locations(location_ids)

Retrieve multiple locations by their IDs.

get_price_components(supply_point_ids)

Retrieve price components for specified supply points.

get_price_data(date_range, price_component_ids)

Retrieve price data for specified components and date range.

get_setpoint_schedule(control_unit, date_range)

Retrieve setpoint schedule from a control unit.

load_measurements(components, date_range)

Load measurement data for specified components and date range.

location_post_setup(location)

Perform post-setup operations on a location.

open()

Open connection to the building management system.

put_setpoint_schedule(schedule, control_unit)

Upload a setpoint schedule to a control unit.

abstract close()

Close connection to the building management system.

This method should clean up resources, close connections, and perform any necessary cleanup operations.

Return type:

None

abstract get_all_locations_collection()

Retrieve a collection containing all available locations.

Returns:

Collection with all locations

Return type:

Collection

abstract get_all_locations_information()

Retrieve information about all available locations.

Returns:

List of location information objects

Return type:

list[LocationInformation]

abstract get_comfort_profile_setpoints(date_range, location)

Retrieve comfort profile setpoints for a location and date range.

Parameters:
  • date_range (DateRange) – Time range for the comfort profiles

  • location (Location | int) – Location object or location ID

Returns:

List of comfort profiles

Return type:

list[ComfortProfile]

abstract get_devices(location_id)

Retrieve all devices for a specific location.

Parameters:

location_id (int) – ID of the location

Returns:

List of devices in the location

Return type:

list[Device]

abstract get_electricity_prices(date_range, unit, include_vat, include_tariff)

Retrieve electricity prices for a unit and date range.

Parameters:
  • unit (Unit) – Unit to get prices for

  • date_range (DateRange) – Time range for the prices

  • include_vat (bool) – Whether to include VAT in prices

  • include_tariff (bool) – Whether to include tariff in prices

Returns:

Electricity price data

Return type:

ElectricityPrices

abstract get_features(location_id)

Retrieve available features for a specific location.

Parameters:

location_id (int) – ID of the location to query

Returns:

Available features for the location

abstract get_location(location_id)

Retrieve a specific location by ID.

Parameters:

location_id (int) – ID of the location to retrieve

Returns:

Location object

Return type:

Location

Raises:

ValueError – If location ID is not found

abstract get_locations(location_ids)

Retrieve multiple locations by their IDs.

Parameters:

location_ids (list[int]) – List of location IDs to retrieve

Returns:

List of location objects

Return type:

list[Location]

Raises:

ValueError – If any location ID is not found

abstract get_price_components(supply_point_ids)

Retrieve price components for specified supply points.

Parameters:

supply_point_ids (list[int]) – List of supply point IDs

Returns:

Dictionary mapping supply point IDs to their price components

Return type:

dict[int, list[AppliedPriceComponent]]

abstract get_price_data(date_range, price_component_ids)

Retrieve price data for specified components and date range.

Parameters:
  • date_range (DateRange) – Time range for the price data

  • price_component_ids (list[int]) – List of price component IDs

Returns:

Dictionary mapping component IDs to their price data

Return type:

dict[int, PriceData]

abstract get_setpoint_schedule(control_unit, date_range)

Retrieve setpoint schedule from a control unit.

Parameters:
  • control_unit (Unit) – Control unit to query

  • date_range (DateRange) – Time range for the schedule

Returns:

Setpoint schedule

Return type:

SetpointSchedule

abstract load_measurements(components, date_range)

Load measurement data for specified components and date range.

This method loads measurement data into the components’ internal storage, typically for later retrieval or analysis.

Parameters:
  • components (list[Component]) – List of components to load measurements for

  • date_range (DateRange) – Time range for the measurements

Raises:

ValueError – If components or date range is invalid

Return type:

None

location_post_setup(location)

Perform post-setup operations on a location.

This method is called after a location has been created and allows the adapter to perform any additional setup or configuration.

Parameters:

location (Location) – Location that was just created

Return type:

None

Example:
>>> # Default implementation does nothing
>>> class TestAdapter(Adapter):
...     def location_post_setup(self, location):
...         pass  # Custom setup logic would go here
>>>
>>> # Method exists and is callable
>>> hasattr(Adapter, 'location_post_setup')
True
abstract open()

Open connection to the building management system.

This method should establish any necessary connections, authenticate, and prepare the adapter for data operations.

Raises:

ConnectionError – If connection cannot be established

Return type:

None

abstract put_setpoint_schedule(schedule, control_unit)

Upload a setpoint schedule to a control unit.

Parameters:
  • schedule (SetpointSchedule) – Setpoint schedule to upload

  • control_unit (Unit) – Control unit to receive the schedule

Returns:

HTTP response from the upload operation

Return type:

Response

Raises:

ValueError – If schedule or control unit is invalid