caspia.pan.rules package

Submodules

caspia.pan.rules.base module

class caspia.pan.rules.base.RuleActivator(rule)[source]

Bases: object

Implements some rule logic.

WARMUP_DURATION = 120.0
async activate(warmup=True)[source]

Activate the rule.

classmethod can_activate_rule(rule)[source]
async deactivate()[source]

Deactivate the rule.

async do_activate()[source]

To be implemented by subclasses.

async do_deactivate()[source]

To be implemented by subclasses.

running_status(message=None)[source]

Set status to RUNNING and then to FAILURE or READY (contextmanager).

property state

Tuple of RuleState and optional message.

exception caspia.pan.rules.base.RuleNotReadyError(message)[source]

Bases: Exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class caspia.pan.rules.base.RuleState[source]

Bases: enum.Enum

An enumeration.

FAILURE = 'failure'
READY = 'ready'
RUNNING = 'running'
SETUP = 'setup'
WAITING = 'waiting'
property warning_level

caspia.pan.rules.blindscontrol module

class caspia.pan.rules.blindscontrol.AngleRange(start, end)[source]

Bases: object

class caspia.pan.rules.blindscontrol.BlindsControl(name, storage)[source]

Bases: caspia.meadow.client.gateway.ServiceGatewayMixin, caspia.meadow.services.blindscontrol.BlindsControlBase

Initialize new service.

Parameters
  • name – Name of the service (or just its path)

  • include – What optional characteristics to include. Tuple of their names.

class Mode

Bases: enum.Enum

An enumeration.

BLOCK_DIRECT_SUN_DOWN = 'block-direct-sun-or-down'
BLOCK_DIRECT_SUN_UP = 'block-direct-sun-or-up'
MANUAL = 'manual'
property all_observables
attach(connection)
property attached
auto_discovery = True
characteristic_cached_read(characteristic)
characteristic_cached_write(characteristic, value_and_meta)
async characteristic_read(characteristic, **kwargs)[source]

Read value of the characteristic.

Parameters
  • characteristic – The characteristic to which the value should be written.

  • value – The value to be written.

  • kwargs – Dictionary with extra key (dictionary with metadata) and optionally a timeout (float specifing explicit timeout for the operation).

Returns

Tuple (value, extra).

characteristic_subscribe(characteristic, on_value, on_error=None)
async characteristic_write(characteristic, value, **kwargs)[source]

Write a value to the characteristic.

Parameters
  • characteristic – The characteristic to which the value should be written.

  • value – The value to be written.

  • kwargs – Dictionary with extra key (dictionary with metadata) and optionally a timeout (float specifing explicit timeout for the operation).

characteristics = {'$metadata': <Characteristic <class 'caspia.meadow.services.base.ServiceMeta'>:$metadata>, 'mode': <Characteristic <class 'caspia.meadow.services.base.ServiceMeta'>:mode>}
detach()
static get_subclass(stype, mixin=None)
load_definition(spec)

Update characteristics of this instance based on serialized specs.

Parameters

spec – Dict most likely going to be coming from meadow - from some gateway informing us about its services and their characteristics.

metadata
mode
async notify(characteristic, value, if_changed=False, extra=None)
on(name, *args, **kwargs)
optional = {}
async published()
serialize()

Return serialized version (most likely dict) if possible or None.

type = 'blinds-control'
class caspia.pan.rules.blindscontrol.BlindsControlRule(horizontal_view, vertical_view, blinds_seg_width, blinds_seg_spacing, blinds, sun=None, identifier=None)[source]

Bases: caspia.meadow.rules.base.Rule

Identifier will become the BlindsControl’s service name. Name of the rule will be filled automatically.

build_identifier()

Builds unique identifier for this rule.

classmethod deserialize(data, context)
enable_duplicates = False
property identifier
serialize()

Return serialized version (most likely dict) if possible or None.

serialize_content()

Subclasses should override this and return serialized self. If the instance cannot be serialized, return None. identifer key must not be included.

serialized_type = None
class caspia.pan.rules.blindscontrol.BlindsControlRuleActivator(rule)[source]

Bases: caspia.pan.rules.base.RuleActivator

WARMUP_DURATION = 120.0
async activate(warmup=True)

Activate the rule.

classmethod can_activate_rule(rule)[source]
async deactivate()

Deactivate the rule.

async do_activate()[source]

To be implemented by subclasses.

do_control
async do_deactivate()[source]

To be implemented by subclasses.

running_status(message=None)

Set status to RUNNING and then to FAILURE or READY (contextmanager).

property state

Tuple of RuleState and optional message.

class caspia.pan.rules.blindscontrol.Calc[source]

Bases: object

static blind_angle_(width, spacing, angle)[source]
static blinds_blocking_angle(width, spacing, angle)[source]

Given a current position of a sun and size of blind’s segments, calculate the minimum blind’s angle blocking all sunlight.

static blinds_current_view(width, spacing, angle)[source]

Given blind’s width, spacing and current angle, calculate the view from inside out. :param width: width of the blind’s segments :param spacing: vertical spacing of segments :param angle: current angle of the segments in radians :returns: range of vertical view (tuple of two angles)

static triangle_beta(a, b, c, gama)[source]

Calculates angle beta of a triangle with given edge lengths a and b and given angle gama (in radians).

static triangle_c(a, b, gama)[source]

Calculate length of third side given two sides and angle between them.

caspia.pan.rules.lightgroup module

class caspia.pan.rules.lightgroup.LightGroupAttachRuleActivator(rule)[source]

Bases: caspia.pan.rules.base.RuleActivator

WARMUP_DURATION = 120.0
async activate(warmup=True)

Activate the rule.

classmethod can_activate_rule(rule)[source]
async deactivate()

Deactivate the rule.

async do_activate()[source]

To be implemented by subclasses.

async do_deactivate()[source]

To be implemented by subclasses.

async on_group_light_is_on_notification(value, extra)[source]
running_status(message=None)

Set status to RUNNING and then to FAILURE or READY (contextmanager).

property state

Tuple of RuleState and optional message.

caspia.pan.rules.on_do module

class caspia.pan.rules.on_do.OnDoRuleActivator(rule)[source]

Bases: caspia.pan.rules.base.RuleActivator

RETRY_DELAY = 5.0
RETRY_DELAY_MAX = 300.0
WARMUP_DURATION = 120.0
async activate(warmup=True)

Activate the rule.

classmethod can_activate_rule(rule)[source]
async deactivate()

Deactivate the rule.

async do_activate()[source]

To be implemented by subclasses.

async do_deactivate()[source]

To be implemented by subclasses.

evaluation
running_status(message=None)

Set status to RUNNING and then to FAILURE or READY (contextmanager).

property state

Tuple of RuleState and optional message.

caspia.pan.rules.thermostat module

class caspia.pan.rules.thermostat.ThermostatRuleActivator(rule)[source]

Bases: caspia.pan.rules.base.RuleActivator

WARMUP_DURATION = 120.0
async activate(warmup=True)

Activate the rule.

classmethod can_activate_rule(rule)[source]
async deactivate()

Deactivate the rule.

async do_activate()[source]

To be implemented by subclasses.

async do_deactivate()[source]

To be implemented by subclasses.

running_status(message=None)

Set status to RUNNING and then to FAILURE or READY (contextmanager).

property state

Tuple of RuleState and optional message.

Module contents