Appliance
Appliances are entities which group together behavioural rules.
Appliances are abstract non deterministic state machines, they do not know how to turn on your light, they just know that your light should be turned on.
Events are notified to Appliances and can make transit the state machine.
Tip
The Appliance state machine can be modified by a user at any time.
Event processing, inside an Appliance instance, can be disabled/enabled (you can see them grayed out in the example projects).
If, as an example, you have a curtain model automated to be opened by the system when it receives the event home.event.sleepiness.Event.Awake, meaning the user has to be wake up, then the user can inhibit the processing of such an event every time he does not want to be wake up.
Appliances states are designed to be easily reusable.
When writing the state machine one of the most difficult things is to be sure that every transition is correct. For this reason the behaviour of an Appliance is tested and described by a BDD test.
Appliance Class
- class home.Appliance(name: str, events: Iterable[home.Event] = None, events_disabled: Iterable[home.Event] = None)
An abstract representation of a device. An appliance has a state which is changed by notified events.
- property name: str
The Appliance name
- property events: Iterable[home.Event]
A list of Events already notified to the Appliance
- property events_disabled: Iterable[home.Event]
A list of Events disabled in the Appliance state machine
- property state: home.appliance.State
The Appliance state
- property forced_enum: home.Event
An Event capable of making the Appliance forced (if any)
- update(other: home.Appliance) Tuple[home.appliance.State, home.appliance.State]
Update state using events taken from another Appliance
- Parameters
other – look for new events in another Appliance and use them to update Appliance state
- Returns
(old_state, new_state) a tuple with the old state, the state before updating, and the new state, the one after the update.
- update_by(trigger: home.protocol.Trigger, description: home.protocol.Description) Tuple[home.appliance.State, home.appliance.State]
Update state using trigger. A trigger is capable of creating a new state using its method make_new_state_from.
- Parameters
trigger – a trigger capable of making a new state from an old one.
description – a message description taken from a bus event, it carries updated data used to make the new state
- Returns
(old_state, new_state) a tuple with the old state, the state before updating, and the new state, the one after the update.
- notify(event: home.Event) Tuple[home.appliance.State, home.appliance.State]
Notify a new event to the Appliance
- Parameters
event – an event
- Returns
(old_state, new_state) a tuple with the old state, the state before notifying event, and the new state, the one after the notify.
- is_notified(event: home.Event) bool
Event has been notified to the Appliance?
- Parameters
event – an event
- Returns
bool
- is_enabled(event: home.Event) bool
Events of the same given type are enabled in the state machine?
- Parameters
event – an event
- Returns
bool
- enable(event: home.Event)
Enable events of the same given type in the state machine
- Parameters
event – an event
- Returns
bool
- disable(event: home.Event)
Disable events of the same given type in the state machine
- Parameters
event – an event
- Returns
bool