Code Documentation

aioswitcher

Switcher water heater unofficial API and bridge.

aioswitcher.api

Switcher water heater unofficial API and bridge, API Object.

class aioswitcher.api.SwitcherV2Api(loop: asyncio.events.AbstractEventLoop, ip_addr: str, phone_id: str, device_id: str, device_password: str)[source]

Represntation of the SwitcherV2 API object.

Parameters
  • loop – the event loop for the factory to run in.

  • ip_addr – the ip address assigned to the device

  • phone_id – the phone id of the desired device.

  • device_id – the id of the desired device.

  • device_password – the password of the desired device.

Todo

  • control_device takes a timer value that must be converted to hex before calling this method using the deisgnated tool. On the other hand, the rest of the action methods` takes their arguments raw and use the appropriate tool for converting themselves. This is confusing and needs to be adjusted.

async __aenter__()[source]

Enter SwitcherV2Api asynchronous context manager.

Returns

This instance of aioswitcher.api.SwitcherV2Api as an awaitable.

async __await__()[source]

Return SwitcherV2Api awaitable object.

Returns

This instance of aioswitcher.api.SwitcherV2Api.

async __aexit__(exc_type, exc_value, traceback)[source]

Exit SwitcherV2Api asynchronous context manager.

async connect()[source]

Connect to asynchronous socket and get reader and writer object.

async disconnect()[source]

Disconnect from asynchronous socket.

async _full_login()[source]

Use for sending the login packet to the device.

Returns

A tuple of two Tuple[str, Optional[messages.SwitcherV2LoginResponseMSG]].

The first object is a string contianing the hexadecimal representation of the current unix timestamp.

The second object will be An instance of the serialized object aioswitcher.api.messages.SwitcherV2LoginResponseMSG.

Note

This is a private function, please consider using its wrapper function login instead.

async login()[source]

Use as wrapper for sending the login packet to the device.

Returns

An instance of the serialized object aioswitcher.api.messages.SwitcherV2LoginResponseMSG.

async _full_get_state()[source]

Use for sending the get state packet to the device.

Returns

A tuple of three Tuple[str, Optional[messages.SwitcherV2LoginResponseMSG], Optional[messages.SwitcherV2StateResponseMSG]].

The first object is a string contianing the hexadecimal representation of the current unix timestamp.

The second object will be An instance of the serialized object aioswitcher.api.messages.SwitcherV2LoginResponseMSG.

The third object will be An instance of the serialized object aioswitcher.api.messages.SwitcherV2StateResponseMSG.

Note

This is a private function, please consider using its wrapper function get_state instead.

async get_state()[source]

Use as wrapper for sending the get state packet to the device.

Returns

An instance of the serialized object aioswitcher.api.messages.SwitcherV2StateResponseMSG.

async set_auto_shutdown(full_time)[source]

Use for sending the set auto-off packet to the device.

Parameters

full_time – timedelta value containg the configuration value for auto-shutdown. Accepts anythin between 1 and 3 hours.

Returns

An instance of the serialized object aioswitcher.api.messages.SwitcherV2SetAutoOffResponseMSG.

async set_device_name(name)[source]

Use for sending the set name packet to the device.

Parameters

name – string name with the length of 2 >= x >= 32.

Returns

An instance of the serialized object aioswitcher.api.messages.SwitcherV2UpdateNameResponseMSG.

async get_schedules()[source]

Use for retrival of the schedules from the device.

Returns

An instance of the serialized object aioswitcher.api.messages.SwitcherV2GetScheduleResponseMSG.

async disable_enable_schedule(schedule_data)[source]

Use for disabling or enabling a schedule on the device.

Parameters

schedule_data – formatted data for updating the schedule, can be obtained from the aioswitcher.schedules.SwitcherV2Schedule object or created using the format aioswitcher.consts.SCHEDULE_CREATE_DATA_FORMAT filled with three values: weekdays, start-time and end-time. Weekdays can be created using the tool aioswitcher.tools.create_weekdays_value, the start and end times can be created using the aioswitcher.tools.timedelta_str_to_schedule_time

Returns

An instance of the serialized object aioswitcher.api.messages.SwitcherV2DisableEnableScheduleResponseMSG.

async delete_schedule(schedule_id)[source]

Use for deleting a schedule from the device.

Parameters

schedule_id – the id of the schedule slot from the device, can be 0-7 as there are 8 slots available. Can be obtained from the aioswitcher.schedules.SwitcherV2Schedule object.

Returns

An instance of the serialized object aioswitcher.api.messages.SwitcherV2DeleteScheduleResponseMSG.

async create_schedule(schedule_data)[source]

Use for creating a new schedule in the next empty schedule slot.

Parameters

schedule_data – formatted data for updating the schedule, can be created using the format aioswitcher.consts.SCHEDULE_CREATE_DATA_FORMAT filled with three values: weekdays, start-time and end-time. Weekdays can be created using the tool aioswitcher.tools.create_weekdays_value, the start and end times can be created using the aioswitcher.tools.timedelta_str_to_schedule_time

Returns

An instance of the serialized object aioswitcher.api.messages.SwitcherV2CreateScheduleResponseMSG.

property connected

Return true if api is connected.

Type

bool

aioswitcher.api.messages

Switcher Packet Response Messages.

class aioswitcher.api.messages.ResponseMessageType

Bases: enum.Enum

An enumeration.

class aioswitcher.api.messages.SwitcherV2BaseResponseMSG(loop: asyncio.events.AbstractEventLoop, response: bytes, msg_type: aioswitcher.api.messages.ResponseMessageType)[source]

Represntation of the switcher v2 base response message.

Parameters
  • loop – the event loop to perform actions in.

  • response – the raw response from the device.

  • msg_type – the message type as described in the ‘’ResponseMessageType’’ Enum class.

property msg_type

the message type.

Type

aioswitcher.api.messages.ResponseMessageType

property successful

Indicating whether or not the request was successful.

Type

bool

property unparsed_response

Return The raw response from the device.

Type

bytes

class aioswitcher.api.messages.SwitcherV2ControlResponseMSG(loop: asyncio.events.AbstractEventLoop, response: bytes)[source]

Bases: aioswitcher.api.messages.SwitcherV2BaseResponseMSG

Represntation of the switcher v2 control response message.

Parameters
  • loop – the event loop to perform actions in.

  • response – the raw response from the device.

property msg_type

the message type.

Type

aioswitcher.api.messages.ResponseMessageType

property successful

Indicating whether or not the request was successful.

Type

bool

property unparsed_response

Return The raw response from the device.

Type

bytes

class aioswitcher.api.messages.SwitcherV2CreateScheduleResponseMSG(loop: asyncio.events.AbstractEventLoop, response: bytes)[source]

Bases: aioswitcher.api.messages.SwitcherV2BaseResponseMSG

Represntation of the switcher v2 create schedule response message.

Parameters
  • loop – the event loop to perform actions in.

  • response – the raw response from the device.

property msg_type

the message type.

Type

aioswitcher.api.messages.ResponseMessageType

property successful

Indicating whether or not the request was successful.

Type

bool

property unparsed_response

Return The raw response from the device.

Type

bytes

class aioswitcher.api.messages.SwitcherV2DeleteScheduleResponseMSG(loop: asyncio.events.AbstractEventLoop, response: bytes)[source]

Bases: aioswitcher.api.messages.SwitcherV2BaseResponseMSG

Represntation of the switcher v2 delete schedule response message.

Parameters
  • loop – the event loop to perform actions in.

  • response – the raw response from the device.

property msg_type

the message type.

Type

aioswitcher.api.messages.ResponseMessageType

property successful

Indicating whether or not the request was successful.

Type

bool

property unparsed_response

Return The raw response from the device.

Type

bytes

class aioswitcher.api.messages.SwitcherV2DisableEnableScheduleResponseMSG(loop: asyncio.events.AbstractEventLoop, response: bytes)[source]

Bases: aioswitcher.api.messages.SwitcherV2BaseResponseMSG

Represntation of the switcher v2 dis/en schedule response message.

Parameters
  • loop – the event loop to perform actions in.

  • response – the raw response from the device.

property msg_type

the message type.

Type

aioswitcher.api.messages.ResponseMessageType

property successful

Indicating whether or not the request was successful.

Type

bool

property unparsed_response

Return The raw response from the device.

Type

bytes

class aioswitcher.api.messages.SwitcherV2GetScheduleResponseMSG(loop: asyncio.events.AbstractEventLoop, response: bytes)[source]

Bases: aioswitcher.api.messages.SwitcherV2BaseResponseMSG

represnation of the switcher v2 get schedule message.

Parameters
  • loop – the event loop to perform actions in.

  • response – the raw response from the device.

Todo

  • the get_schedules attribute should be a method.

  • schdule_detais is __init__ is yielding List[str] instead of List[bytes], that’s not supposed to happen.

property found_schedules

Return true if found schedules in the response.

Type

bool

property get_schedules

Return schedules.

Type

list(aioswitcher.schedules.SwitcherV2Schedule)

property msg_type

the message type.

Type

aioswitcher.api.messages.ResponseMessageType

property successful

Indicating whether or not the request was successful.

Type

bool

property unparsed_response

Return The raw response from the device.

Type

bytes

class aioswitcher.api.messages.SwitcherV2LoginResponseMSG(loop: asyncio.events.AbstractEventLoop, response: bytes)[source]

Bases: aioswitcher.api.messages.SwitcherV2BaseResponseMSG

Represntation of the switcher v2 login response message.

Parameters
  • loop – the event loop to perform actions in.

  • response – the raw response from the device.

property msg_type

the message type.

Type

aioswitcher.api.messages.ResponseMessageType

property session_id

Return the retrieved session id.

Type

str

property successful

Indicating whether or not the request was successful.

Type

bool

property unparsed_response

Return The raw response from the device.

Type

bytes

class aioswitcher.api.messages.SwitcherV2SetAutoOffResponseMSG(loop: asyncio.events.AbstractEventLoop, response: bytes)[source]

Bases: aioswitcher.api.messages.SwitcherV2BaseResponseMSG

Represntation of the switcher v2 set auto-off response message.

Parameters
  • loop – the event loop to perform actions in.

  • response – the raw response from the device.

property msg_type

the message type.

Type

aioswitcher.api.messages.ResponseMessageType

property successful

Indicating whether or not the request was successful.

Type

bool

property unparsed_response

Return The raw response from the device.

Type

bytes

class aioswitcher.api.messages.SwitcherV2StateResponseMSG(loop: asyncio.events.AbstractEventLoop, response: bytes)[source]

Bases: aioswitcher.api.messages.SwitcherV2BaseResponseMSG

Represntation of the switcher v2 state response message.

Parameters
  • loop – the event loop to perform actions in.

  • response – the raw response from the device.

Todo

  • replace init_future attribute with get_init_future method.

async initialize(response)[source]

Finish the initialization of the message and update the future object.

Parameters

response – the raw response from the device.

property auto_off

Return the auto-off configuration value.

Type

str

property current

Return the power consumption in amps.

Type

float

property init_future

Return the future of the initialization.

Type

asyncio.Future

async initialize(response: bytes) → None[source]

Finish the initialization of the message and update the future object.

Parameters

response – the raw response from the device.

property msg_type

the message type.

Type

aioswitcher.api.messages.ResponseMessageType

property power

Return the current power consumption in watts.

Type

int

property state

Return the state.

Type

str

property successful

Indicating whether or not the request was successful.

Type

bool

property time_left

Return the time left to auto-off.

Type

str

property unparsed_response

Return The raw response from the device.

Type

bytes

class aioswitcher.api.messages.SwitcherV2UpdateNameResponseMSG(loop: asyncio.events.AbstractEventLoop, response: bytes)[source]

Bases: aioswitcher.api.messages.SwitcherV2BaseResponseMSG

Represntation of the switcher v2 update name response message.

Parameters
  • loop – the event loop to perform actions in.

  • response – the raw response from the device.

property msg_type

the message type.

Type

aioswitcher.api.messages.ResponseMessageType

property successful

Indicating whether or not the request was successful.

Type

bool

property unparsed_response

Return The raw response from the device.

Type

bytes

aioswitcher.api.packets

Switcher water heater unofficial API and bridge, API Packet formats.

aioswitcher.bridge

Switcher water heater unofficial API and bridge, Bridge Object.

class aioswitcher.bridge.SwitcherV2Bridge(loop: asyncio.events.AbstractEventLoop, phone_id: str, device_id: str, device_password: str)[source]

Represntation of the SwitcherV2 Bridge object.

Parameters
  • loop – the event loop for the factory to run in.

  • phone_id – the phone id of the desired device.

  • device_id – the id of the desired device.

  • device_password – the password of the desired device.

Todo

  • replace queue attribute with get_queue method.

async __aenter__()[source]

Enter SwitcherV2Bridge asynchronous context manager.

Returns

This instance of aioswitcher.bridge.SwitcherV2Bridge as an awaitable.

async __await__()[source]

Return SwitcherV2Bridge awaitable object.

Returns

This instance of aioswitcher.bridge.SwitcherV2Bridge.

async __aexit__(exc_type, exc_value, traceback)[source]

Exit the SwitcherV2Bridge asynchronous context manager.

async start()[source]

Create an asynchronous listenr and start the bridge event.

async stop()[source]

Stop the asynchronous bridge.

property queue

Return the queue storing updated device objects.

Type

asyncio.Queue

property running

Return true if bridge is running.

Type

bool

aioswitcher.bridge.messages

Switcher Bridge Response Messages.

class aioswitcher.bridge.messages.SwitcherV2BroadcastMSG(loop: asyncio.events.AbstractEventLoop, message: Union[bytes, str])[source]

Represntation of the SwitcherV2 broadcast message.

Parameters
  • loop – the event loop to perform actions in.

  • message – the raw message from the device.

Todo

  • replace init_future attribute with get_init_future method.

async initialize(message)[source]

Finish the initialization and update the future object.

Parameters

message – the raw message from the device.

property auto_off_set

Return the auto-off configuration value.

Type

str

property current

Return the power consumptionin amps.

Type

float

property device_id

Return the device id.

Type

str

property device_state

Return the state of the device.

Type

str

property init_future

Return the future of the device initialization.

Type

asyncio.Future

property ip_address

Return the ip address.

Type

str

property mac_address

Return the mac address.

Type

str

property name

Return the device name.

Type

str

property power

Return the power consumptionin watts.

Type

int

property remaining_time_to_off

Return the time left to auto-off.

Type

str

property verified

Return whether or not the message is a SwitcherV2 message.

Type

bool

aioswitcher.consts

Switcher water heater unofficial API and bridge, Global constants.

aioswitcher.devices

Switcher water heater unofficial API and bridge, Device classes.

class aioswitcher.devices.SwitcherV2Device(device_id: str, ip_address: str, mac_address: str, name: str, state: str, remaining_time: Optional[str], auto_off_set: str, power_consumption: int, electric_current: float, phone_id: str, device_password: str, last_state_change: datetime.datetime)[source]

Represntation of the switcherv2 device.

Parameters
  • device_id – the id retrieved from the device.

  • ip_address – the ip address assigned to the device.

  • mac_address – the mac address assigned to the device.

  • name – the name of the device.

  • state – the current state of the device (in/off).

  • remaining_time – remaining time (if on).

  • auto_off_set – configured value for auto shutdown.

  • power_consumption – the current power consumpstion in watts.

  • electric_current – the current power consumpstion in amps.

  • phone_id – the phone id retrieved from the device.

  • device_password – the password retrieved from the device.

  • last_state_change – datetime of the last state change.

update_device_data(ip_address, name, state, remaining_time, auto_off_set, power_consumption, electric_current, last_state_change)[source]

Update the device state and data.

Parameters
  • ip_address – the ip address assigned to the device.

  • name – the name of the device.

  • state – the current state of the device (on/off).

  • remaining_time – remaining time (if on).

  • auto_off_set – configured value for auto shutdown.

  • power_consumption – the current power consumpstion in watts.

  • electric_current – the current power consumpstion in amps.

  • last_state_change – datetime of the last state change.

as_dict()[source]

Return as dict.

Returns

A dictionary represntation of the object properties. Used to make the object json serializable.

property auto_off_set

Returns the auto-off configuration value.

Type

str

property device_id

Returns the device id.

Type

str

property device_password

Returns the device password.

Type

str

property electric_current

returns the power consumption in amps.

Type

float

property ip_addr

Returns the ip address.

Type

str

property last_data_update

Returns timestamp of the last update.

Type

datetime

property last_state_change

Returns timestamp of the last state change.

Type

datetime

property mac_addr

Returns the mac address.

Type

str

property name

Returns the device name.

Type

str

property phone_id

Returns the phone id.

Type

str

property power_consumption

Returns the power consumption in watts.

Type

int

property remaining_time

Returns the time left to auto shutdown.

Type

str

property state

Returns the device state.

Type

str

aioswitcher.errors

Switcher water heater unofficial API and bridge, Exception classes.

exception aioswitcher.errors.CalculationError[source]

Bases: Exception

Exception to be raised when cpu bound calculation is failing.

with_traceback()

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

exception aioswitcher.errors.DecodingError[source]

Bases: Exception

Exception to be raised when cpu bound decoding is failing.

with_traceback()

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

exception aioswitcher.errors.EncodingError[source]

Bases: Exception

Exception to be raised when cpu bound encoding is failing.

with_traceback()

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

aioswitcher.protocols

Switcher water heater unofficial API and bridge, Network protocols.

class aioswitcher.protocols.SwitcherV2UdpProtocolFactory(loop: asyncio.events.AbstractEventLoop, phone_id: str, device_id: str, device_password: str, queue: asyncio.queues.Queue, run_factory_evt: asyncio.locks.Event)[source]

Bases: asyncio.protocols.DatagramProtocol

Represntation of the Asyncio UDP protocol factory.

Parameters
  • loop – the event loop for the factory to run in.

  • phone_id – the phone id of the desired device.

  • device_id – the id of the desired device.

  • device_password – the password of the desired device.

  • queue – a asyncio.Queue for the factory to save messages in.

  • asyncio.Event for signaling the factory to run. (run_factory_evt) –

Todo

  • replace factory_future attribute with get_factory_future method.

connection_made(transport)[source]

Call on connection established.

datagram_received(data, addr)[source]

Call on datagram recieved.

error_received(exc)[source]

Call on exception recieved.

connection_lost(exc)[source]

Call on connection lost.

close_transport(future)[source]

Call for closing the transport.

async handle_incoming_messages(data, addr)[source]

Use for Handling incoming messages.

get_device_from_message(ip_addr, future)[source]

Use for extracting the device from the broadcast message.

close_transport(future: _asyncio.Future) → None[source]

Call for closing the transport.

connection_lost(exc: Optional[Exception]) → None[source]

Call on connection lost.

connection_made(transport: asyncio.transports.BaseTransport) → None[source]

Call on connection established.

datagram_received(data: Union[bytes, str], addr: Tuple) → None[source]

Call on datagram recieved.

error_received(exc: Optional[Exception]) → None[source]

Call on exception recieved.

property factory_future

Representing the initialization status.

Type

asyncio.Future

get_device_from_message(ip_addr: str, future: _asyncio.Future) → None[source]

Use for extracting the device from the broadcast message.

async handle_incoming_messages(data: Union[bytes, str], addr: Tuple) → None[source]

Use for Handling incoming messages.

pause_writing()

Called when the transport’s buffer goes over the high-water mark.

Pause and resume calls are paired – pause_writing() is called once when the buffer goes strictly over the high-water mark (even if subsequent writes increases the buffer size even more), and eventually resume_writing() is called once when the buffer size reaches the low-water mark.

Note that if the buffer size equals the high-water mark, pause_writing() is not called – it must go strictly over. Conversely, resume_writing() is called when the buffer size is equal or lower than the low-water mark. These end conditions are important to ensure that things go as expected when either mark is zero.

NOTE: This is the only Protocol callback that is not called through EventLoop.call_soon() – if it were, it would have no effect when it’s most needed (when the app keeps writing without yielding until pause_writing() is called).

resume_writing()

Called when the transport’s buffer drains below the low-water mark.

See pause_writing() for details.

aioswitcher.schedules

Switcher water heater unofficial API and bridge, Schedules.

class aioswitcher.schedules.SwitcherV2Schedule(loop: asyncio.events.AbstractEventLoop, idx: int, schedule_details: List[bytes])[source]

Represnation of the SwitcherV2 schedule slot.

Parameters
  • loop – the event loop to perform schedule operation in.

  • idx – the index of the schedule slot (0-7).

  • schedule_details – the string raw schedule data details.

Todo

  • Replace init_future attribute with get_init_future method.

async initialize(idx, schedule_details)[source]

Finish the initialization of the schedule.

as_dict()[source]

Return as dict.

Returns

A dictionary represntation of the object properties. Used to make the object json serializable.

property days

Return the weekdays of the schedule.

Type

list(str)

property duration

Return the duration of the schedule.

Type

str

property enabled

Return true if enabled, setter included.

Type

bool

property end_time

Return the end time of the schedule.

Type

str

property init_future

Return the future of the initialization.

Type

asyncio.Future

property recurring

Return true if recurring.

Type

bool

property schedule_data

Return the schedule data, setter included.

Type

bytes

property schedule_id

Return the schedule id.

Type

str

property start_time

Return the start time of the schedule.

Type

str

schedules._calc_next_run_for_schedule(schedule_details)

Calculate the next runtime of the schedule.

Parameters

schedule_detailsSwitcherV2Schedule representing the schedule slot.

Returns

A pretty string describing the next due run. e.g. “Due tommorow at 17:00”.

Note

This is a private function containing blocking code. Please consider using calc_next_run_for_schedule (without the _), to schedule as a task on the event loop.

async schedules.calc_next_run_for_schedule(loop, schedule_details)

Asynchronous wrapper for _calc_next_run_for_schedule.

Use as async wrapper for calling _calc_next_run_for_schedule, calculating the next runtime of the schedule.

Parameters
  • loop – the event loop to execute the function in.

  • schedule_detailsSwitcherV2Schedule representing the schedule slot.

Returns

A pretty string describing the next due run. e.g. “Due tommorow at 17:00”.

aioswitcher.tools

Switcher water heater unofficial API and bridge, Tools and Helpers.

aioswitcher.tools._convert_minutes_to_timer(minutes: str) → str[source]

Convert on-timer minutes to hexadecimal before sending.

Parameters

minutes – on-timer minutes to convert.

Returns

Hexadecimal represntation of the mintues argument.

Raises

aioswitcher.erros.EncodingError – when failed hexlify.

Note

This is a private function containing blocking code. Please consider using convert_minutes_to_timer (without the _), to schedule as a task in the event loop.

aioswitcher.tools._convert_seconds_to_iso_time(all_seconds: int) → str[source]

Convert seconds to iso time.

Parameters

all_seconds – the total number of seconds to convert.

Returns

%M:%S format. e.g. “02:24:37”.

Return type

A string represnting the converted iso time in %H

Raises

aioswitcher.erros.CalculationError – when failed to convert the argument.

Note

This is a private function containing blocking code. Please consider using convert_seconds_to_iso_time (without the _), to schedule as a task in the event loop.

aioswitcher.tools._convert_string_to_device_name(name: str) → str[source]

Convert string device name to hexadecimal before sending.

Parameters

name – the desired name for conerting.

Returns

Hexadecimal represntation of the name argument.

Raises

aioswitcher.erros.EncodingError – when failed hexlify.

Note

This is a private function containing blocking code. Please consider using convert_string_to_device_name (without the _), to schedule as a task in the event loop.

aioswitcher.tools._convert_timedelta_to_auto_off(full_time: datetime.timedelta) → str[source]

Convert timedelta object for auto-shutdown to hexadecimal.

Parameters

full_time – timedelta object represnting the auto-shutdown time.

Returns

Hexadecimal represntation of the full_time argument.

Raises

aioswitcher.erros.EncodingError – when failed hexlify.

Note

This is a private function containing blocking code. Please consider using convert_timedelta_to_auto_off (without the _), to schedule as a task in the event loop.

aioswitcher.tools._crc_sign_full_packet_com_key(data: str) → str[source]

Calculate the crc for packets before send.

Parameters

data – packet data to sign.

Returns

The calculated and signed packet data.

Raises

aioswitcher.erros.EncodingError – when failed to sign the packet.

Note

This is a private function containing blocking code. Please consider using crc_sign_full_packet_com_key (without the _), to schedule as a task in the event loop.

aioswitcher.tools._create_weekdays_value(requested_days: List[int]) → str[source]

Create hex value from list of requested days for schedule updating.

Parameters

data – list of integers represnting the requested days. check aioswitcher.consts for the correct values.

Returns

Hexadecimal representation of the days list.

Raises

aioswitcher.erros.EncodingError – when failed to convert the argument.

Note

This is a private function containing blocking code. Please consider using create_weekdays_value (without the _), to schedule as a task in the event loop.

aioswitcher.tools._get_days_list_from_bytes(data: int) → List[str][source]

Extract week days from shcedule bytes data.

Parameters

data – bytes representing the days list.

Returns

List of string represntation the week days included in the list. See aioswitcher.consts for days literals.

Raises

aioswitcher.erros.DecodingError – when failed to analyze the argument.

Note

This is a private function containing blocking code. Please consider using get_days_list_from_bytes (without the _), to schedule as a task in the event loop.

aioswitcher.tools._get_time_from_bytes(data: bytes) → str[source]

Extract start/end time from schedule bytes.

Parameters

data – bytes representing the start or the end time for the schedule.

Returns

%M format. e.g. “20:30”.

Return type

Time string in %H

Raises

aioswitcher.erros.DecodingError – when failed to analyze the argument.

Note

This is a private function containing blocking code. Please consider using get_time_from_bytes (without the _), to schedule as a task in the event loop.

aioswitcher.tools._get_timestamp() → str[source]

Generate hexadecimal represntation of the current timestamp.

Returns

Hexadecimal represntation of the current unix time retrieved by time.time.

Raises

aioswitcher.erros.DecodingError – when failed to analyze the timestamp.

Note

This is a private function containing blocking code. Please consider using get_timestamp (without the _), to schedule as a task in the event loop.

aioswitcher.tools._timedelta_str_to_schedule_time(time_value: str) → str[source]

Convert time string to schedule start/end time to hexadecimale.

Parameters

data – time to convert. e.g. “21:00”.

Returns

Hexadecimal representation of time_value argument.

Raises

aioswitcher.erros.EncodingError – when failed to convert the argument.

Note

This is a private function containing blocking code. Please consider using timedelta_str_to_schedule_time (without the _), to schedule as a task in the event loop.

async aioswitcher.tools.convert_minutes_to_timer(loop: asyncio.events.AbstractEventLoop, minutes: str) → str[source]

Asynchronous wrapper for _convert_minutes_to_timer.

Use as async wrapper for calling _convert_minutes_to_timer, converting on-timer minutes to hexadecimal.

Parameters

minutes – on-timer minutes to convert.

Returns

Hexadecimal represntation of the mintues argument.

async aioswitcher.tools.convert_seconds_to_iso_time(loop: asyncio.events.AbstractEventLoop, all_seconds: int) → str[source]

Asynchronous wrapper for _convert_seconds_to_iso_time.

Use as async wrapper for calling _convert_seconds_to_iso_time, calculating the next runtime of the schedule.

Parameters
  • loop – the event loop to execute the function in.

  • all_seconds – the total number of seconds to convert.

Returns

%M:%S format. e.g. “02:24:37”.

Return type

A string represnting the converted iso time in %H

async aioswitcher.tools.convert_string_to_device_name(loop: asyncio.events.AbstractEventLoop, name: str) → str[source]

Asynchronous wrapper for _convert_string_to_device_name.

Use as async wrapper for calling _convert_string_to_device_name, converting name to hexadecimal.

Parameters

name – the desired name for conerting.

Returns

Hexadecimal represntation of the name argument.

async aioswitcher.tools.convert_timedelta_to_auto_off(loop: asyncio.events.AbstractEventLoop, full_time: datetime.timedelta) → str[source]

Asynchronous wrapper for _convert_timedelta_to_auto_off.

Use as async wrapper for calling _convert_timedelta_to_auto_off, converting timedelta auto-shutdown configuration to hexadecimal.

Parameters

full_time – timedelta object represnting the auto-shutdown time.

Returns

Hexadecimal represntation of the full_time argument.

async aioswitcher.tools.crc_sign_full_packet_com_key(loop: asyncio.events.AbstractEventLoop, data: str) → str[source]

Asynchronous wrapper for _crc_sign_full_packet_com_key.

Use as async wrapper for calling _crc_sign_full_packet_com_key, performing crc sign to the packet data.

Parameters

data – packet data to sign.

Returns

The calculated and signed packet data.

async aioswitcher.tools.create_weekdays_value(loop: asyncio.events.AbstractEventLoop, requested_days: List[int]) → str[source]

Asynchronous wrapper for _create_weekdays_value.

Use as async wrapper for calling _create_weekdays_value, creating hex value from list of requested days for schedule updating.

Parameters

data – list of integers represnting the requested days. check aioswitcher.consts for the correct values.

Returns

Hexadecimal representation of the days list.

async aioswitcher.tools.get_days_list_from_bytes(loop: asyncio.events.AbstractEventLoop, data: int) → List[str][source]

Asynchronous wrapper for _get_days_list_from_bytes.

Use as async wrapper for calling _get_days_list_from_bytes, extracting week days from shcedule bytes data.

Parameters

data – bytes representing the days list.

Returns

List of string represntation the week days included in the list. See aioswitcher.consts for days literals.

async aioswitcher.tools.get_time_from_bytes(loop: asyncio.events.AbstractEventLoop, data: bytes) → str[source]

Asynchronous wrapper for _get_time_from_bytes.

Use as async wrapper for calling _get_time_from_bytes, extracting start/end time from schedule bytes data.

Parameters

data – bytes representing the start or the end time for the schedule.

Returns

%M format. e.g. “20:30”.

Return type

Time string in %H

async aioswitcher.tools.get_timestamp(loop: asyncio.events.AbstractEventLoop) → str[source]

Asynchronous wrapper for _get_timestamp.

Use as async wrapper for calling _get_timestamp, creating hexadecimal represntation of the current timestamp.

Returns

Hexadecimal represntation of the current unix time retrieved by time.time.

async aioswitcher.tools.timedelta_str_to_schedule_time(loop: asyncio.events.AbstractEventLoop, time_value: str) → str[source]

Asynchronous wrapper for _timedelta_str_to_schedule_time.

Use as async wrapper for calling _timedelta_str_to_schedule_time, converting time string to schedule start/end time to hexadecimale.

Parameters

data – time to convert. e.g. “21:00”.

Returns

Hexadecimal representation of time_value argument.