preheat_open.building_unit.BuildingUnit

class preheat_open.building_unit.BuildingUnit(unit_type, unit_data, building_ref)

Bases: BaseBuildingUnit

Building Unit; an extension of BaseBuildingUnit to handle subUnits

__init__(unit_type, unit_data, building_ref)

Methods

__init__(unit_type, unit_data, building_ref)

add_sub_unit(u)

children()

rtype:

list[BaseBuildingUnit]

clear_data([clear_children])

Clears data from the unit

clear_state(**kwargs)

Clears the state data from the unit

cquery(name)

rtype:

Component

describe([display, prefix, children])

Generate a text-based description of a unit

get_all_component_cids([prefix, components])

get_all_component_details([prefix, components])

rtype:

list[dict[str, Union[str, float, None]]]

get_all_component_ids([prefix, components])

rtype:

dict[str, str]

get_component(name)

Returns the component with the given name

get_state([update, estimate, seconds_back, ...])

Fetches the state for the given unit (to force refresh it, update is required)

get_zones()

has_component(component_name)

Tells if a unit a given component

has_data([component, check_not_null])

Tells whether the unit has data

is_shared()

rtype:

bool

load_data(start, end[, resolution, ...])

Loads data in the unit

load_state([seconds_back, t_now, ...])

Loads the state of the unit at a given point in time

parents()

rtype:

list[BaseBuildingUnit]

qpu(*args, **kwargs)

rtype:

Union[BaseBuildingUnit, list[BaseBuildingUnit]]

qu(*args, **kwargs)

rtype:

Union[BaseBuildingUnit, list[BaseBuildingUnit]]

query_parent_units([unit_type, name, ...])

rtype:

list[BaseBuildingUnit]

query_units([unit_type, name, ...])

rtype:

list[BaseBuildingUnit]

Attributes

weather

clear_data(clear_children=False)

Clears data from the unit

Parameters:

kwargs

/

Return type:

None

Returns:

/

clear_state(**kwargs)

Clears the state data from the unit

Parameters:

kwargs

/

Return type:

None

Returns:

/

describe(display=True, prefix='', children=True, **kwargs)

Generate a text-based description of a unit

Parameters:
  • display (bool) – if True, prints the output

  • prefix (str) – string prefix to each output line (use for tabs, etc)

  • components – if True, outputs components details

  • show_subtype – if True, shows the sub-type of units

  • kwargs

    /

Return type:

str

Returns:

text description of units as string

get_component(name)

Returns the component with the given name

Parameters:

name (str) – name of the component to look for

Raise:

NotFoundError if no component with the given name is found

Return type:

Component

Returns:

component with the chosen name

get_state(update=False, estimate='last', seconds_back=300, t_now=None, by='id', resolution_overwrite=None)

Fetches the state for the given unit (to force refresh it, update is required)

Parameters:
  • update (bool) – if True, loads the state data to update it, else just fetches the state already loaded

  • estimate (str) – method to use for state estimation (“last” for last available value, “mean” for average in period, “median” for median value in period)

  • seconds_back (int) – number of seconds before t_now to look for when loading data

  • t_now (Optional[datetime]) – now-time override

  • by (str) – whether to load data by “id” or component id “cid”

  • resolution_overwrite (Optional[str]) – if specified, then loads the data using that specific resolution (by default, data is loaded in “raw” resolution if t_now is more recent than 7 days ago, else “5min”)

Return type:

Series

Returns:

unit state in pandas Series format

has_component(component_name)

Tells if a unit a given component

Parameters:

component_name (str) – name of the component to look for

Return type:

bool

Returns:

True if the unit has a component with the given name, False otherwise

has_data(component=None, check_not_null=True)

Tells whether the unit has data

Parameters:
  • component (Optional[str]) – if non-None, tells whether data is available for the specific component

  • check_not_null (bool) – if True, checks that the data is not null

Return type:

bool

Returns:

True if data is available, False otherwise

load_data(start, end, resolution='minute', load_children=False, components=None, **kwargs)

Loads data in the unit

Parameters:
  • start (Union[str, datetime]) – start of the period to load data for

  • end (Union[str, datetime]) – end of the period to load data for

  • resolution (Union[str, Enum]) – resolution to load data with (raw, 5min, minute, hour, day, week, month, year)

  • components – components to restrict the loading to (None: no restriction)

  • kwargs

    /

Return type:

None

Returns:

/

load_state(seconds_back=300, t_now=None, resolution_overwrite=None)

Loads the state of the unit at a given point in time

Parameters:
  • seconds_back (int) – number of seconds back prior to t_now to look for data for (if none is found in the interval, then value will be NaN for this component)

  • t_now (Optional[datetime]) – now-time override

  • resolution_overwrite (Optional[str]) – if specified, then loads the data using that specific resolution (by default, data is loaded in “raw” resolution if t_now is more recent than 7 days ago, else “5min”)

Return type:

None

Returns:

/