preheat_open.building_unit.BaseBuildingUnit¶
- class preheat_open.building_unit.BaseBuildingUnit(unit_type, unit_data, building_ref, load_data_by='id')¶
Bases:
Unit
Building Unit; an extension of Unit to handle zones and parent units
- __init__(unit_type, unit_data, building_ref, load_data_by='id')¶
Methods
__init__
(unit_type, unit_data, building_ref)clear_data
(**kwargs)Clears data from the unit
clear_state
(**kwargs)Clears the state data from the unit
cquery
(name)- rtype:
describe
([display, prefix, components, ...])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, components])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
(*args, **kwargs)- rtype:
list
[BaseBuildingUnit
]
Attributes
weather
- clear_data(**kwargs)¶
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='', components=True, show_subtype=True, **kwargs)¶
Generate a text-based description of a unit
- Parameters:
display (
bool
) – if True, prints the outputprefix (
str
) – string prefix to each output line (use for tabs, etc)components (
bool
) – if True, outputs components detailsshow_subtype (
bool
) – if True, shows the sub-type of unitskwargs –
/
- 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:
- 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 loadedestimate (
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 datat_now (
Optional
[datetime
]) – now-time overrideby (
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 componentcheck_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', components=None, **kwargs)¶
Loads data in the unit
- Parameters:
start (
Union
[str
,datetime
]) – start of the period to load data forend (
Union
[str
,datetime
]) – end of the period to load data forresolution (
Union
[str
,Enum
]) – resolution to load data with (raw, 5min, minute, hour, day, week, month, year)components (
Optional
[list
[str
]]) – 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 overrideresolution_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:
/