API Reference
This section contains the complete API documentation for the Gecko IoT Client.
Main Client
- class gecko_iot_client.GeckoIotClient(idd, transporter, config_timeout=5.0)[source]
Bases:
objectMain client for interacting with Gecko IoT devices.
The GeckoIotClient provides a high-level interface for connecting to and controlling Gecko IoT devices through various transport protocols (e.g., MQTT via AWS IoT). It handles device configuration, state management, and zone control.
- Parameters:
idd (
str) – Unique identifier for the device/clienttransporter (
AbstractTransporter) – Transport layer implementation for communicationconfig_timeout (
float) – Maximum time to wait for configuration loading in seconds (default: 30.0)
Example
>>> from gecko_iot_client import GeckoIotClient >>> from gecko_iot_client.transporters.mqtt import MqttTransporter >>> >>> transporter = MqttTransporter( ... endpoint="your-endpoint.amazonaws.com", ... certificate_path="cert.pem.crt", ... private_key_path="private.pem.key", ... ca_file_path="AmazonRootCA1.pem" ... ) >>> >>> with GeckoIotClient("device-123", transporter) as client: ... zones = client.get_zones() ... print(f"Found {len(zones)} zone types")
- __init__(idd, transporter, config_timeout=5.0)[source]
- Parameters:
idd (
str)transporter (
AbstractTransporter)config_timeout (
float)
- connect()[source]
Establish connection to the device and initialize configuration.
This method sets up event handlers for configuration and state changes, connects to the transport layer, and automatically loads the device configuration.
- Raises:
Exception – If connection or configuration loading fails
- __enter__()[source]
Enter the context manager.
Automatically calls connect() when entering the context.
- Returns:
Self for use in with statement
- Return type:
- __exit__(exc_type, exc_val, exc_tb)[source]
Exit the context manager.
Automatically calls disconnect() when exiting the context.
- Parameters:
exc_type – Exception type if an exception occurred
exc_val – Exception value if an exception occurred
exc_tb – Exception traceback if an exception occurred
- property is_connected: bool
Check if the client is currently connected.
This checks both MQTT connectivity and device shadow connectivity status.
- Returns:
True if fully connected (MQTT + gateway + vessel), False otherwise
- Return type:
- disconnect()[source]
Disconnect from the device and clean up resources.
This method properly closes the transport connection and performs any necessary cleanup.
- property connectivity_status: ConnectivityStatus
Get current connectivity status.
- Returns:
Current connectivity including MQTT, gateway, and vessel status
- Return type:
- property operation_mode_controller: OperationModeController
Get the operation mode controller for read/write operations.
- Returns:
Controller for operation mode functionality
- Return type:
- property operation_mode_status: OperationModeController
Get current operation mode status (legacy property - use operation_mode_controller instead).
- Returns:
Current operation mode controller
- Return type:
- on(channel, callback)[source]
Register a callback for a specific event channel.
- Parameters:
channel (
EventChannel) – The event channel to listen tocallback (
Callable) – Function to call when the event occurs
- Return type:
- off(channel, callback)[source]
Unregister a callback from a specific event channel.
- Parameters:
channel (
EventChannel) – The event channel to stop listening tocallback (
Callable) – The callback function to remove
- Return type:
- get_zones()[source]
Return the parsed zones organized by type.
- Return type:
- Returns:
Dict mapping zone types to lists of zones of that type. Returns a copy to prevent external modification.
- get_zones_by_type(zone_type)[source]
Return all zones of a specific type.
- Parameters:
zone_type (
ZoneType) – The type of zones to retrieve- Return type:
- Returns:
List of zones matching the specified type
- get_zone_by_id_and_type(zone_type, zone_id)[source]
Find and return a zone by its type and ID.
- Parameters:
- Return type:
- Returns:
The zone with matching type and ID
- on_zone_update(callback)[source]
Register callback for zone updates (legacy method).
This method is maintained for backward compatibility. New code should use: client.on(EventChannel.ZONE_UPDATE, callback)
- register_zone_callbacks()[source]
Register callbacks for zone monitoring (legacy method).
This method is maintained for backward compatibility. For new code, use the event system: client.on(EventChannel.ZONE_UPDATE, callback)
- class gecko_iot_client.AbstractTransporter[source]
Bases:
objectAbstract base class for transport layer implementations.
This class defines the interface for communicating with Gecko IoT devices through various protocols (MQTT, HTTP, etc.). Concrete implementations handle the protocol-specific details while providing a unified interface for the client.
- change_state(new_state)[source]
Request a state change on the device.
- Parameters:
new_state – The new state to apply
- Raises:
NotImplementedError – Must be implemented by subclasses
- connect()[source]
Establish connection to the transport medium.
- Raises:
NotImplementedError – Must be implemented by subclasses
- disconnect()[source]
Close connection and clean up resources.
- Raises:
NotImplementedError – Must be implemented by subclasses
- is_connected()[source]
Check if the transport is currently connected.
- Returns:
True if connected, False otherwise
- Return type:
- Raises:
NotImplementedError – Must be implemented by subclasses
- load_configuration(timeout=30.0)[source]
Load device configuration from the transport medium.
- Parameters:
timeout (
float) – Maximum time to wait for configuration response in seconds- Raises:
NotImplementedError – Must be implemented by subclasses
- load_state()[source]
Load current device state from the transport medium.
- Raises:
NotImplementedError – Must be implemented by subclasses
- on_configuration_loaded(callback)[source]
Register callback for configuration load events.
- Parameters:
callback – Function to call when configuration is loaded
- Raises:
NotImplementedError – Must be implemented by subclasses
- on_connectivity_change(callback)[source]
Register callback for connectivity changes.
- Parameters:
callback – Function to call when connectivity status changes. Callback should accept a boolean (True=connected, False=disconnected).
- Raises:
NotImplementedError – Must be implemented by subclasses
- on_state_change(callback)[source]
Register callback for state change notifications.
- Parameters:
callback – Function to call when state changes occur
- Raises:
NotImplementedError – Must be implemented by subclasses
- on_state_loaded(callback)[source]
Register callback for state load events.
- Parameters:
callback – Function to call when state is loaded
- Raises:
NotImplementedError – Must be implemented by subclasses
- publish_batch_desired_state(zone_updates)[source]
Publish desired state updates for multiple zones in a single operation.
- publish_desired_state(desired_state)[source]
Publish desired state updates to the transport medium.
- Parameters:
desired_state (
Dict[str,Any]) – Dictionary of desired state structure to publish- Return type:
Future- Returns:
Future that resolves when update is published
Note
The actual transport implementation (MQTT, HTTP, etc.) handles the protocol-specific details like topics, payloads, field naming. This method is transport-agnostic and doesn’t impose any business logic about zones, features, or other domain concepts.
- exception gecko_iot_client.ConfigurationTimeoutError[source]
Bases:
ConfigurationErrorRaised when configuration request times out.
- class gecko_iot_client.AbstractZone(id, zone_type, config, name=None)[source]
Bases:
objectBase zone class with change callback functionality
- classmethod from_config(zone_id, config, zone_type)[source]
Create a zone instance from configuration data.
- classmethod from_state_dict(state_dict)[source]
Deserialize a zone from a complete state dictionary.
- classmethod register_zone_type(zone_type)[source]
Decorator to register a zone class with its type
- Parameters:
zone_type (
ZoneType)
- set_publish_callback(callback)[source]
Set the callback function for publishing desired state updates.
- class gecko_iot_client.ZoneType(*values)[source]
Bases:
Enum- FLOW_ZONE = 'flow'
- TEMPERATURE_CONTROL_ZONE = 'temperatureControl'
- LIGHTING_ZONE = 'lighting'
- class gecko_iot_client.TemperatureControlZone(zone_id, config)[source]
Bases:
AbstractZoneState representation for temperature control zone v1 with validation
- ZONE_TYPE = 'temperatureControl'
- property mode: TemperatureControlMode | None
- set_target_temperature(temperature)[source]
Set target temperature with validation against configured limits.
- property status: TemperatureControlZoneStatus | None
- class gecko_iot_client.FlowZone(zone_id, config)[source]
Bases:
AbstractZoneState representation for flow zone v1 with validation
- Parameters:
zone_id (
str)config (
FlowConfiguration)
- ZONE_TYPE = 'flow'
- __init__(zone_id, config)[source]
Initialize FlowZone with zone_id and config.
- Parameters:
zone_id (
str)config (
FlowConfiguration)
- property capabilities: List[FlowZoneCapabilities]
Get the capabilities of the flow zone.
- property initiators: List[FlowZoneInitiator] | None
- property presets: List[FlowZonePreset]
Get the speed presets for the flow zone, if supported.
- property speed_config: SpeedConfig | None
Get speed configuration if it exists and is properly structured.
- property type: FlowZoneType
Get the type of the flow zone.
- class gecko_iot_client.LightingZone(zone_id, config)[source]
Bases:
AbstractZoneState representation for lighting zone v1 with validation
- ZONE_TYPE = 'lighting'
- class gecko_iot_client.EventChannel(*values)[source]
Bases:
EnumEvent channels for different types of notifications.
- CONNECTIVITY_UPDATE = 'connectivity_update'
- OPERATION_MODE_UPDATE = 'operation_mode_update'
- ZONE_UPDATE = 'zone_update'
- SENSOR_UPDATE = 'sensor_update'
- STATE_UPDATE = 'state_update'
- CONFIGURATION_UPDATE = 'configuration_update'
- class gecko_iot_client.EventEmitter[source]
Bases:
objectEvent emitter for managing callbacks across different channels.
This provides a unified way to handle different types of events that can occur in the Gecko IoT client.
- clear(channel=None)[source]
Clear callbacks for a specific channel or all channels.
- Parameters:
channel (
EventChannel|None) – Optional specific channel to clear. If None, clears all.- Return type:
- emit(channel, data=None)[source]
Emit an event to all registered callbacks for a channel.
- Parameters:
channel (
EventChannel) – The event channel to emit todata (
Any) – Optional data to pass to the callbacks
- Return type:
- off(channel, callback)[source]
Unregister a callback from a specific event channel.
- Parameters:
channel (
EventChannel) – The event channel to stop listening tocallback (
Callable) – The callback function to remove
- Return type:
- on(channel, callback)[source]
Register a callback for a specific event channel.
- Parameters:
channel (
EventChannel) – The event channel to listen tocallback (
Callable) – Function to call when the event occurs
- Return type:
- class gecko_iot_client.ConnectivityStatus(transport_connected=False, gateway_status='UNKNOWN', vessel_status='UNKNOWN')[source]
Bases:
objectData structure for connectivity status information.
- classmethod from_state_data(state_data, transport_connected=False)[source]
Create ConnectivityStatus from device shadow state data.
- Parameters:
- Return type:
- Returns:
ConnectivityStatus object with extracted connectivity info
- property is_fully_connected: bool
Check if the device is fully connected.
- Returns:
True if transport is connected and both gateway and vessel are in good state
- class gecko_iot_client.OperationMode(*values)[source]
Bases:
EnumEnum for operation modes (watercare modes).
- classmethod from_value(value)[source]
Convert a value to OperationMode enum.
- Parameters:
value (
Any) – The value to convert (int, str, or OperationMode)- Return type:
- Returns:
OperationMode enum value, defaults to OTHER for unknown values
- AWAY = 0
- STANDARD = 1
- SAVINGS = 2
- SUPER_SAVINGS = 3
- WEEKENDER = 4
- OTHER = 5
- class gecko_iot_client.OperationModeStatus(operation_mode=OperationMode.OTHER)[source]
Bases:
objectData structure for operation mode (watercare) status information.
- Parameters:
operation_mode (
OperationMode)
- __init__(operation_mode=OperationMode.OTHER)[source]
Initialize operation mode status.
- Parameters:
operation_mode (
OperationMode) – Current operation mode
- classmethod from_state_data(state_data)[source]
Create OperationModeStatus from device shadow state data.
- property is_energy_saving: bool
Check if the current mode is an energy-saving mode.
- Returns:
True if mode is SAVINGS, SUPER_SAVINGS, or AWAY
- class gecko_iot_client.OperationModeController[source]
Bases:
objectController for operation mode (watercare mode) with read/write capabilities.
Similar to zone classes, this handles both state parsing and control commands for the operation mode functionality.
- classmethod from_state_data(state_data)[source]
Create OperationModeController from device shadow state data.
- property is_energy_saving: bool
Check if the current mode is an energy-saving mode.
- Returns:
True if mode is SAVINGS, SUPER_SAVINGS, or AWAY
- property mode_name: str
Get the human-readable name of the current operation mode.
- Returns:
String representation of the operation mode
- set_mode(mode)[source]
Set the operation mode.
- Parameters:
mode (
OperationMode) – The operation mode to set- Return type:
- class gecko_iot_client.GeckoApiClient(websession, api_url=API_BASE_URL, auth0_url=AUTH0_BASE_URL)[source]
Bases:
ABCProvide Gecko authentication tied to an OAuth2 based config entry.
- __init__(websession, api_url=API_BASE_URL, auth0_url=AUTH0_BASE_URL)[source]
Initialize Gecko auth.
- abstractmethod async async_get_access_token()[source]
Return a valid access token for the Gecko API.
- Return type:
- async async_get_monitor_livestream(monitor_id)[source]
Get MQTT livestream connection details for a monitor.
Models Package
Models package for GeckoIotClient.
- class gecko_iot_client.models.TemperatureControlZoneStatus(*values)[source]
Bases:
EnumEnum for temperature control zone status
- IDLE = 0
- HEATING = 1
- COOLING = 2
- INVALID = 3
- HEAT_PUMP_HEATING = 4
- HEAT_PUMP_AND_HEATER_HEATING = 5
- HEAT_PUMP_COOLING = 6
- HEAT_PUMP_DEFROSTING = 7
- HEAT_PUMP_ERROR = 8
- class gecko_iot_client.models.TemperatureControlMode(eco=False)[source]
Bases:
objectTemperature control mode configuration
- Parameters:
eco (
bool)
- class gecko_iot_client.models.FlowZoneInitiator(*values)[source]
Bases:
EnumEnum for flow zone initiators
- USER_DEMAND = 'UD'
- CHECKFLOW = 'CF'
- PURGE = 'PU'
- FILTRATION = 'FI'
- HEATING = 'HT'
- COOLDOWN = 'CD'
- HEAT_PUMP = 'HTP'
- class gecko_iot_client.models.FlowZoneCapabilities(*values)[source]
Bases:
EnumEnum for flow zone capabilities
- SUPPORTS_SPEED_PRESETS = 'supports_speed_presets'
- SUPPORTS_SPEED_PERCENTAGE = 'supports_speed_percentage'
- SUPPORTS_TURN_ON = 'supports_turn_on'
- SUPPORTS_TURN_OFF = 'supports_turn_off'
- class gecko_iot_client.models.RGB(r, g, b, i=None)[source]
Bases:
objectRGB color representation
- class gecko_iot_client.models.ZoneConfigurationParser[source]
Bases:
objectSimple parser for zone configurations.
- ZONE_TYPES = {'flow': ZoneType.FLOW_ZONE, 'lighting': ZoneType.LIGHTING_ZONE, 'temperatureControl': ZoneType.TEMPERATURE_CONTROL_ZONE}
- ZONE_TYPE_TO_CLASS = {ZoneType.FLOW_ZONE: <class 'gecko_iot_client.models.flow_zone.FlowZone'>, ZoneType.LIGHTING_ZONE: <class 'gecko_iot_client.models.lighting_zone.LightingZone'>, ZoneType.TEMPERATURE_CONTROL_ZONE: <class 'gecko_iot_client.models.temperature_control_zone.TemperatureControlZone'>}
Zone Types
- class gecko_iot_client.models.abstract_zone.ZoneType(*values)[source]
Bases:
Enum- FLOW_ZONE = 'flow'
- TEMPERATURE_CONTROL_ZONE = 'temperatureControl'
- LIGHTING_ZONE = 'lighting'
- class gecko_iot_client.models.abstract_zone.AbstractZone(id, zone_type, config, name=None)[source]
Bases:
objectBase zone class with change callback functionality
- set_publish_callback(callback)[source]
Set the callback function for publishing desired state updates.
- classmethod register_zone_type(zone_type)[source]
Decorator to register a zone class with its type
- Parameters:
zone_type (
ZoneType)
- classmethod from_config(zone_id, config, zone_type)[source]
Create a zone instance from configuration data.
- classmethod from_state_dict(state_dict)[source]
Deserialize a zone from a complete state dictionary.
- update_from_config(config)[source]
Update zone from configuration data (structure, limits, capabilities).
- gecko_iot_client.models.abstract_zone.create_zone_logger(zone_name)[source]
Create a logging callback for zone changes
- gecko_iot_client.models.abstract_zone.create_validation_callback(attribute, validator, error_message='Invalid value')[source]
Create a validation callback for specific attributes
- class gecko_iot_client.models.temperature_control_zone.TemperatureControlZoneStatus(*values)[source]
Bases:
EnumEnum for temperature control zone status
- IDLE = 0
- HEATING = 1
- COOLING = 2
- INVALID = 3
- HEAT_PUMP_HEATING = 4
- HEAT_PUMP_AND_HEATER_HEATING = 5
- HEAT_PUMP_COOLING = 6
- HEAT_PUMP_DEFROSTING = 7
- HEAT_PUMP_ERROR = 8
- class gecko_iot_client.models.temperature_control_zone.TemperatureControlMode(eco=False)[source]
Bases:
objectTemperature control mode configuration
- Parameters:
eco (
bool)
- class gecko_iot_client.models.temperature_control_zone.TemperatureControlZone(zone_id, config)[source]
Bases:
AbstractZoneState representation for temperature control zone v1 with validation
- status_: Optional[TemperatureControlZoneStatus]
- temperature_: Optional[float]
- mode_: Optional[TemperatureControlMode]
- set_point: Optional[float]
- property status: TemperatureControlZoneStatus | None
- property mode: TemperatureControlMode | None
- set_target_temperature(temperature)[source]
Set target temperature with validation against configured limits.
- ZONE_TYPE = 'temperatureControl'
- class gecko_iot_client.models.flow_zone.FlowConfiguration[source]
Bases:
TypedDict-
speed:
SpeedConfig
-
speed:
- class gecko_iot_client.models.flow_zone.FlowZoneCapabilities(*values)[source]
Bases:
EnumEnum for flow zone capabilities
- SUPPORTS_SPEED_PRESETS = 'supports_speed_presets'
- SUPPORTS_SPEED_PERCENTAGE = 'supports_speed_percentage'
- SUPPORTS_TURN_ON = 'supports_turn_on'
- SUPPORTS_TURN_OFF = 'supports_turn_off'
- class gecko_iot_client.models.flow_zone.FlowZoneInitiator(*values)[source]
Bases:
EnumEnum for flow zone initiators
- USER_DEMAND = 'UD'
- CHECKFLOW = 'CF'
- PURGE = 'PU'
- FILTRATION = 'FI'
- HEATING = 'HT'
- COOLDOWN = 'CD'
- HEAT_PUMP = 'HTP'
- class gecko_iot_client.models.flow_zone.FlowZoneType(*values)[source]
Bases:
Enum- FLOW_ZONE = 'flow_zone'
- WATERFALL_ZONE = 'waterfall_zone'
- BLOWER_ZONE = 'blower_zone'
- class gecko_iot_client.models.flow_zone.FlowZoneTypeProperties(format_name)[source]
Bases:
objectProperties for different flow zone types.
- Parameters:
format_name (
callable)
-
format_name:
callable
- __init__(format_name)
- Parameters:
format_name (
callable)
- class gecko_iot_client.models.flow_zone.FlowZone(zone_id, config)[source]
Bases:
AbstractZoneState representation for flow zone v1 with validation
- Parameters:
zone_id (
str)config (
FlowConfiguration)
- __init__(zone_id, config)[source]
Initialize FlowZone with zone_id and config.
- Parameters:
zone_id (
str)config (
FlowConfiguration)
- active: Optional[bool]
- speed: Optional[float]
- initiators_: Optional[List[FlowZoneInitiator]]
- property speed_config: SpeedConfig | None
Get speed configuration if it exists and is properly structured.
- property initiators: List[FlowZoneInitiator] | None
- property type: FlowZoneType
Get the type of the flow zone.
- property capabilities: List[FlowZoneCapabilities]
Get the capabilities of the flow zone.
- property presets: List[FlowZonePreset]
Get the speed presets for the flow zone, if supported.
- ZONE_TYPE = 'flow'
- class gecko_iot_client.models.lighting_zone.RGB(r, g, b, i=None)[source]
Bases:
objectRGB color representation
- class gecko_iot_client.models.lighting_zone.LightingZone(zone_id, config)[source]
Bases:
AbstractZoneState representation for lighting zone v1 with validation
- active: Optional[bool]
- rgbi: Optional[RGB]
- effect: Optional[str]
- update_from_state(state)[source]
Update lighting zone from runtime state with special handling for RGBI.
- ZONE_TYPE = 'lighting'
Configuration and State Management
Zone configuration parser module.
Simple parser for converting zone configurations into zone instances.
- class gecko_iot_client.models.zone_parser.ZoneConfigurationParser[source]
Bases:
objectSimple parser for zone configurations.
- ZONE_TYPES = {'flow': ZoneType.FLOW_ZONE, 'lighting': ZoneType.LIGHTING_ZONE, 'temperatureControl': ZoneType.TEMPERATURE_CONTROL_ZONE}
- ZONE_TYPE_TO_CLASS = {ZoneType.FLOW_ZONE: <class 'gecko_iot_client.models.flow_zone.FlowZone'>, ZoneType.LIGHTING_ZONE: <class 'gecko_iot_client.models.lighting_zone.LightingZone'>, ZoneType.TEMPERATURE_CONTROL_ZONE: <class 'gecko_iot_client.models.temperature_control_zone.TemperatureControlZone'>}
Operation mode (watercare) model for Gecko IoT devices.
- class gecko_iot_client.models.operation_mode.OperationMode(*values)[source]
Bases:
EnumEnum for operation modes (watercare modes).
- AWAY = 0
- STANDARD = 1
- SAVINGS = 2
- SUPER_SAVINGS = 3
- WEEKENDER = 4
- OTHER = 5
- class gecko_iot_client.models.operation_mode.OperationModeStatus(operation_mode=OperationMode.OTHER)[source]
Bases:
objectData structure for operation mode (watercare) status information.
- Parameters:
operation_mode (
OperationMode)
- __init__(operation_mode=OperationMode.OTHER)[source]
Initialize operation mode status.
- Parameters:
operation_mode (
OperationMode) – Current operation mode
- classmethod from_state_data(state_data)[source]
Create OperationModeStatus from device shadow state data.
- property mode_name: str
Get the human-readable name of the current operation mode.
- Returns:
String representation of the operation mode
Connectivity status model for Gecko IoT devices.
- class gecko_iot_client.models.connectivity.ConnectivityStatus(transport_connected=False, gateway_status='UNKNOWN', vessel_status='UNKNOWN')[source]
Bases:
objectData structure for connectivity status information.
- classmethod from_state_data(state_data, transport_connected=False)[source]
Create ConnectivityStatus from device shadow state data.
- Parameters:
- Return type:
- Returns:
ConnectivityStatus object with extracted connectivity info
Event system for Gecko IoT Client notifications.
- class gecko_iot_client.models.events.EventChannel(*values)[source]
Bases:
EnumEvent channels for different types of notifications.
- CONNECTIVITY_UPDATE = 'connectivity_update'
- OPERATION_MODE_UPDATE = 'operation_mode_update'
- ZONE_UPDATE = 'zone_update'
- SENSOR_UPDATE = 'sensor_update'
- STATE_UPDATE = 'state_update'
- CONFIGURATION_UPDATE = 'configuration_update'
- class gecko_iot_client.models.events.EventEmitter[source]
Bases:
objectEvent emitter for managing callbacks across different channels.
This provides a unified way to handle different types of events that can occur in the Gecko IoT client.
- on(channel, callback)[source]
Register a callback for a specific event channel.
- Parameters:
channel (
EventChannel) – The event channel to listen tocallback (
Callable) – Function to call when the event occurs
- Return type:
- off(channel, callback)[source]
Unregister a callback from a specific event channel.
- Parameters:
channel (
EventChannel) – The event channel to stop listening tocallback (
Callable) – The callback function to remove
- Return type:
- emit(channel, data=None)[source]
Emit an event to all registered callbacks for a channel.
- Parameters:
channel (
EventChannel) – The event channel to emit todata (
Any) – Optional data to pass to the callbacks
- Return type:
- clear(channel=None)[source]
Clear callbacks for a specific channel or all channels.
- Parameters:
channel (
EventChannel|None) – Optional specific channel to clear. If None, clears all.- Return type:
Transporters Package
- class gecko_iot_client.transporters.AbstractTransporter[source]
Bases:
objectAbstract base class for transport layer implementations.
This class defines the interface for communicating with Gecko IoT devices through various protocols (MQTT, HTTP, etc.). Concrete implementations handle the protocol-specific details while providing a unified interface for the client.
- connect()[source]
Establish connection to the transport medium.
- Raises:
NotImplementedError – Must be implemented by subclasses
- disconnect()[source]
Close connection and clean up resources.
- Raises:
NotImplementedError – Must be implemented by subclasses
- on_state_change(callback)[source]
Register callback for state change notifications.
- Parameters:
callback – Function to call when state changes occur
- Raises:
NotImplementedError – Must be implemented by subclasses
- change_state(new_state)[source]
Request a state change on the device.
- Parameters:
new_state – The new state to apply
- Raises:
NotImplementedError – Must be implemented by subclasses
- load_configuration(timeout=30.0)[source]
Load device configuration from the transport medium.
- Parameters:
timeout (
float) – Maximum time to wait for configuration response in seconds- Raises:
NotImplementedError – Must be implemented by subclasses
- on_configuration_loaded(callback)[source]
Register callback for configuration load events.
- Parameters:
callback – Function to call when configuration is loaded
- Raises:
NotImplementedError – Must be implemented by subclasses
- load_state()[source]
Load current device state from the transport medium.
- Raises:
NotImplementedError – Must be implemented by subclasses
- on_state_loaded(callback)[source]
Register callback for state load events.
- Parameters:
callback – Function to call when state is loaded
- Raises:
NotImplementedError – Must be implemented by subclasses
- on_connectivity_change(callback)[source]
Register callback for connectivity changes.
- Parameters:
callback – Function to call when connectivity status changes. Callback should accept a boolean (True=connected, False=disconnected).
- Raises:
NotImplementedError – Must be implemented by subclasses
- is_connected()[source]
Check if the transport is currently connected.
- Returns:
True if connected, False otherwise
- Return type:
- Raises:
NotImplementedError – Must be implemented by subclasses
- publish_desired_state(desired_state)[source]
Publish desired state updates to the transport medium.
- Parameters:
desired_state (
Dict[str,Any]) – Dictionary of desired state structure to publish- Return type:
Future- Returns:
Future that resolves when update is published
Note
The actual transport implementation (MQTT, HTTP, etc.) handles the protocol-specific details like topics, payloads, field naming. This method is transport-agnostic and doesn’t impose any business logic about zones, features, or other domain concepts.
MQTT Transport
MQTT transporter package for Gecko IoT devices.
This package provides MQTT5 connectivity for AWS IoT Core with JWT token authentication, automatic token refresh, and Gecko-specific shadow operations.
Main exports: - MqttTransporter: High-level Gecko IoT transporter (primary interface) - MqttClient: Low-level MQTT protocol client (for advanced use)
- class gecko_iot_client.transporters.mqtt.MqttTransporter(broker_url, monitor_id, token_refresh_callback=None, token_refresh_buffer_seconds=300)[source]
Bases:
AbstractTransporterGecko-specific MQTT transporter.
Responsibilities: - Gecko topic structure (config, state, shadow) - Token refresh and expiration management - Configuration and state loading - AbstractTransporter interface implementation - Reconnection logic with token refresh
This class contains all Gecko IoT business logic and delegates MQTT protocol operations to MqttClient.
- Parameters:
- __init__(broker_url, monitor_id, token_refresh_callback=None, token_refresh_buffer_seconds=300)[source]
Initialize MQTT transporter with Gecko-specific logic.
- load_configuration(timeout=30.0)[source]
Load configuration from AWS IoT.
- Parameters:
timeout (
float)
- publish_batch_desired_state(zone_updates)[source]
Publish batch desired state updates for multiple zones.
- class gecko_iot_client.transporters.mqtt.MqttClient(on_connected=None, on_message=None)[source]
Bases:
objectLow-level MQTT client for AWS IoT Core.
Responsibilities: - Connection/disconnection to AWS IoT MQTT broker - Publishing messages - Subscribing to topics - Message routing to handlers - Connection lifecycle callbacks
This class handles pure MQTT protocol concerns without any Gecko-specific business logic.
- Parameters:
- clear_intentional_disconnect_flag()[source]
Clear the intentional disconnect flag after reconnection.
- Return type:
Connection Management
Connection state manager for MQTT transporter.
- class gecko_iot_client.transporters.connection_state.ConnectionState(*values)[source]
Bases:
EnumMQTT connection states.
- DISCONNECTED = 'disconnected'
- CONNECTING = 'connecting'
- CONNECTED = 'connected'
- RECONNECTING = 'reconnecting'
- CONNECTION_FAILED = 'connection_failed'
- DISCONNECTING = 'disconnecting'
- CREDENTIAL_REFRESH_FAILED = 'credential_refresh_failed'
- class gecko_iot_client.transporters.connection_state.ConnectionEvent(state, timestamp, message=None, error=None)[source]
Bases:
objectConnection state change event.
- Parameters:
-
state:
ConnectionState
- class gecko_iot_client.transporters.connection_state.ConnectionStateManager(reconnect_enabled=True, max_reconnect_attempts=5, initial_retry_delay=1.0, max_retry_delay=60.0, backoff_multiplier=2.0)[source]
Bases:
objectManages connection state and provides reconnection logic.
- Parameters:
- __init__(reconnect_enabled=True, max_reconnect_attempts=5, initial_retry_delay=1.0, max_retry_delay=60.0, backoff_multiplier=2.0)[source]
Initialize connection state manager.
- Parameters:
reconnect_enabled (
bool) – Whether automatic reconnection is enabledmax_reconnect_attempts (
int) – Maximum number of reconnection attemptsinitial_retry_delay (
float) – Initial delay between reconnection attempts (seconds)max_retry_delay (
float) – Maximum delay between reconnection attempts (seconds)backoff_multiplier (
float) – Multiplier for exponential backoff
- add_state_change_callback(callback)[source]
Add a callback to be notified of state changes.
- Parameters:
callback (
Callable[[ConnectionEvent],None])
- remove_state_change_callback(callback)[source]
Remove a state change callback.
- Parameters:
callback (
Callable[[ConnectionEvent],None])
- set_reconnect_callback(callback)[source]
Set the callback function to call when attempting reconnection.
- set_state(new_state, message=None, error=None)[source]
Set the connection state and notify callbacks.
- Parameters:
new_state (
ConnectionState) – The new connection statemessage (
str) – Optional message describing the state changeerror (
Exception) – Optional error that caused the state change
Token manager for handling AWS IoT token refresh and expiration.
- class gecko_iot_client.transporters.token_manager.TokenManager(token_refresh_callback, refresh_threshold_minutes=15)[source]
Bases:
objectManages AWS IoT tokens with automatic refresh capabilities.
- __init__(token_refresh_callback, refresh_threshold_minutes=15)[source]
Initialize the token manager.
- set_token(token_data)[source]
Set the current token and start refresh monitoring.
- Parameters:
token_data (
dict) – Dictionary containing token and expiry information Expected keys: ‘access_token’, ‘expires_in’ or ‘expires_at’
- refresh_token()[source]
Manually refresh the token.
- Return type:
- Returns:
New token data
- Raises:
TokenRefreshError – If refresh fails
Configuration and Logging
Logging configuration for MQTT transporter.
- class gecko_iot_client.transporters.logging_config.MqttTransporterLogger(name='gecko_iot_mqtt', level=logging.INFO, log_file=None, max_file_size=10 * 1024 * 1024, backup_count=5, include_console=True)[source]
Bases:
objectCustom logger configuration for MQTT transporter with structured logging.
- Parameters:
- class gecko_iot_client.transporters.logging_config.ConnectionEventLogger(base_logger)[source]
Bases:
objectSpecialized logger for connection events with metrics tracking.
- Parameters:
base_logger (
Logger)
Exceptions
Custom exceptions for MQTT transporter operations.
- exception gecko_iot_client.transporters.exceptions.MqttTransporterError[source]
Bases:
ExceptionBase exception class for MQTT transporter errors.
- exception gecko_iot_client.transporters.exceptions.ConnectionError[source]
Bases:
MqttTransporterErrorRaised when connection to MQTT broker fails.
- exception gecko_iot_client.transporters.exceptions.AuthenticationError[source]
Bases:
MqttTransporterErrorRaised when authentication with MQTT broker fails.
- exception gecko_iot_client.transporters.exceptions.TokenRefreshError[source]
Bases:
MqttTransporterErrorRaised when token refresh operation fails.
- exception gecko_iot_client.transporters.exceptions.DisconnectionError[source]
Bases:
MqttTransporterErrorRaised when disconnection from MQTT broker fails.
- exception gecko_iot_client.transporters.exceptions.ConfigurationError[source]
Bases:
MqttTransporterErrorRaised when configuration is invalid or missing.
- exception gecko_iot_client.transporters.exceptions.ConfigurationTimeoutError[source]
Bases:
ConfigurationErrorRaised when configuration request times out.