Skip to content

Documentation for Base Devices

This is the base device inherited by all device classes. This should NOT be instantiated directly.

All methods and attributes are available on all devices.

VeSyncBaseToggleDevice

VeSyncBaseToggleDevice(
    details: ResponseDeviceDetailsModel,
    manager: VeSync,
    feature_map: DeviceMapTemplate,
)

Bases: VeSyncBaseDevice, Generic[VS_STATE_T]

Base class for VeSync devices that can be toggled on and off.

Parameters:

Name Type Description Default
details ResponseDeviceDetailsModel

Device details from API call.

required
manager VeSync

Manager object for API calls.

required
feature_map DeviceMapTemplate

Device configuration map, will be specific subclass of DeviceMapTemplate based on device type.

required

Attributes:

Name Type Description
state DeviceState

Device state object Each device has a separate state base class in the base_devices module.

last_response ResponseInfo

Last response from API call.

manager VeSync

Manager object for API calls.

device_name str

Name of device.

device_image str

URL for device image.

cid str

Device ID.

connection_type str

Connection type of device.

device_type str

Type of device.

type str

Type of device.

uuid str

UUID of device, not always present.

config_module str

Configuration module of device.

mac_id str

MAC ID of device.

current_firm_version str

Current firmware version of device.

device_region str

Region of device. (US, EU, etc.)

pid str

Product ID of device, pulled by some devices on update.

sub_device_no int

Sub-device number of device.

product_type str

Product type of device.

features dict

Features of device.

Methods:

Name Description
set_timer

Set timer for device.

get_timer

Get timer for device from API.

clear_timer

Clear timer for device from API.

set_state

Set device state attribute.

get_state

Get device state attribute.

update

Update device details.

display

Print formatted static device info to stdout.

to_json

Print JSON API string

to_jsonb

JSON API bytes device details

to_dict

Return device information as a dictionary.

toggle_switch

Toggle device power on or off.

turn_on

Turn device on.

turn_off

Turn device off.

Note

Device states are found in the state attribute in a subclass of DeviceState based on the device type. The DeviceState subclass is located in device the base_devices module.

The last_response attribute is used to store the last response and error information from the API call. See the pyvesync.errors module for more information.

Inherited From VeSyncBaseDevice

Initialize VeSync device base class.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def __init__(self,
             details: ResponseDeviceDetailsModel,
             manager: VeSync,
             feature_map: DeviceMapTemplate
             ) -> None:
    """Initialize VeSync device base class."""
    self._exclude_serialization: list[str] = []
    self.enabled: bool = True
    self.last_response: ResponseInfo | None = None
    self.manager = manager
    self.device_name: str = details.deviceName
    self.device_image: str | None = details.deviceImg
    self.cid: str = details.cid
    self.connection_type: str | None = details.connectionType
    self.device_type: str = details.deviceType
    self.type: str | None = details.type
    self.uuid: str | None = details.uuid
    self.config_module: str = details.configModule
    self.mac_id: str | None = details.macID
    self.current_firm_version = details.currentFirmVersion
    self.device_region: str | None = details.deviceRegion
    self.pid: str | None = None
    self.sub_device_no: int | None = details.subDeviceNo
    # From feature_map
    self.product_type: str = feature_map.product_type
    self.features: list[str] = feature_map.features

Attributes

cid instance-attribute

cid: str = cid

Inherited From VeSyncBaseDevice

config_module instance-attribute

config_module: str = configModule

Inherited From VeSyncBaseDevice

connection_type instance-attribute

connection_type: str | None = connectionType

Inherited From VeSyncBaseDevice

current_firm_version instance-attribute

current_firm_version = currentFirmVersion

Inherited From VeSyncBaseDevice

device_image instance-attribute

device_image: str | None = deviceImg

Inherited From VeSyncBaseDevice

device_name instance-attribute

device_name: str = deviceName

Inherited From VeSyncBaseDevice

device_region instance-attribute

device_region: str | None = deviceRegion

Inherited From VeSyncBaseDevice

device_type instance-attribute

device_type: str = deviceType

Inherited From VeSyncBaseDevice

enabled instance-attribute

enabled: bool = True

Inherited From VeSyncBaseDevice

features instance-attribute

features: list[str] = features

Inherited From VeSyncBaseDevice

firmware_update property

firmware_update: bool

Inherited From VeSyncBaseDevice

Return True if firmware update available.

This is going to be updated.

is_on property

is_on: bool

Inherited From VeSyncBaseDevice

Return true if device is on.

last_response instance-attribute

last_response: ResponseInfo | None = None

Inherited From VeSyncBaseDevice

mac_id instance-attribute

mac_id: str | None = macID

Inherited From VeSyncBaseDevice

manager instance-attribute

manager = manager

Inherited From VeSyncBaseDevice

product_type instance-attribute

product_type: str = product_type

Inherited From VeSyncBaseDevice

state instance-attribute

state: VS_STATE_T

Inherited From VeSyncBaseDevice

sub_device_no instance-attribute

sub_device_no: int | None = subDeviceNo

Inherited From VeSyncBaseDevice

type instance-attribute

type: str | None = type

Inherited From VeSyncBaseDevice

uuid instance-attribute

uuid: str | None = uuid

Inherited From VeSyncBaseDevice

Functions

clear_timer async

clear_timer() -> bool

Inherited From VeSyncBaseDevice

Clear timer for device from API.

This may not be implemented for all devices. Please open an issue if there is an error.

Returns:

Name Type Description
bool bool

True if successful, False otherwise.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
async def clear_timer(self) -> bool:
    """Clear timer for device from API.

    This may not be implemented for all devices. Please open an issue
    if there is an error.

    Returns:
        bool: True if successful, False otherwise.
    """
    logger.debug('Not implemented - clear_timer')
    return False

display

display(state: bool = True) -> None

Inherited From VeSyncBaseDevice

Print formatted static device info to stdout.

Parameters:

Name Type Description Default
state bool

If True, include state in display, defaults to True.

True

Example:

Device Name:..................Living Room Lamp
Model:........................ESL100
Subdevice No:.................0
Type:.........................wifi
CID:..........................1234567890abcdef

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def display(self, state: bool = True) -> None:
    """Print formatted static device info to stdout.

    Args:
        state (bool): If True, include state in display, defaults to True.

    Example:
    ```
    Device Name:..................Living Room Lamp
    Model:........................ESL100
    Subdevice No:.................0
    Type:.........................wifi
    CID:..........................1234567890abcdef
    ```
    """
    # noinspection SpellCheckingInspection
    display_list = [
        ('Device Name:', self.device_name),
        ('Product Type: ', self.product_type),
        ('Model: ', self.device_type),
        ('Subdevice No: ', str(self.sub_device_no)),
        ('Type: ', self.type),
        ('CID: ', self.cid),
        ('Config Module: ', self.config_module),
        ('Connection Type: ', self.connection_type),
        ('Features', self.features),
        ('Last Response: ', self.last_response),
    ]
    if self.uuid is not None:
        display_list.append(('UUID: ', self.uuid))

    for line in display_list:
        print(f'{line[0]:.<30} {line[1]}')
    if state:
        self.state.display()

get_details abstractmethod async

get_details() -> None

Inherited From VeSyncBaseDevice

Get device details.

This method is defined in each device class to contain the logic to pull the device state from the API and update the device's state attribute. The update() method should be called to update the device state.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
@abstractmethod
async def get_details(self) -> None:
    """Get device details.

    This method is defined in each device class to contain
    the logic to pull the device state from the API and update
    the device's `state` attribute. The `update()` method should
    be called to update the device state.
    """

get_state

get_state(state_attr: str) -> Any

Inherited From VeSyncBaseDevice

Get device state attribute.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def get_state(self, state_attr: str) -> Any:  # noqa: ANN401
    """Get device state attribute."""
    return getattr(self.state, state_attr)

get_timer async

get_timer() -> Timer | None

Inherited From VeSyncBaseDevice

Get timer for device from API and set the state.Timer attribute.

This may not be implemented for all devices. Please open an issue if there is an error.

Note

This method may not be implemented for all devices. Please open an issue if there is an error.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
async def get_timer(self) -> Timer | None:
    """Get timer for device from API and set the `state.Timer` attribute.

    This may not be implemented for all devices. Please open an issue
    if there is an error.

    Note:
        This method may not be implemented for all devices. Please
        open an issue if there is an error.
    """
    logger.debug('Not implemented - get_timer')
    return None

set_state

set_state(state_attr: str, stat_value: Any) -> None

Inherited From VeSyncBaseDevice

Set device state attribute.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def set_state(self, state_attr: str, stat_value: Any) -> None:  # noqa: ANN401
    """Set device state attribute."""
    setattr(self, state_attr, stat_value)

set_timer async

set_timer(duration: int, action: str | None = None) -> bool

Inherited From VeSyncBaseDevice

Set timer for device.

This may not be implemented for all devices. Please open an issue if there is an error.

Parameters:

Name Type Description Default
duration int

Duration in seconds.

required
action str | None

Action to take when timer expires.

None

Returns:

Name Type Description
bool bool

True if successful, False otherwise.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
async def set_timer(self, duration: int, action: str | None = None) -> bool:
    """Set timer for device.

    This may not be implemented for all devices. Please open an issue
    if there is an error.

    Args:
        duration (int): Duration in seconds.
        action (str | None): Action to take when timer expires.

    Returns:
        bool: True if successful, False otherwise.
    """
    del duration
    del action
    logger.debug('Not implemented - set_timer')
    return False

to_dict

to_dict(state: bool = True) -> dict[str, Any]

Inherited From VeSyncBaseDevice

Return device information as a dictionary.

Parameters:

Name Type Description Default
state bool

If True, include state in dictionary, defaults to True.

True

Returns:

Type Description
dict[str, Any]

dict[str, Any]: Dictionary containing device information.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def to_dict(self, state: bool = True) -> dict[str, Any]:
    """Return device information as a dictionary.

    Args:
        state (bool): If True, include state in dictionary, defaults to True.

    Returns:
        dict[str, Any]: Dictionary containing device information.
    """
    device_dict = {
        "device_name": self.device_name,
        "product_type": self.product_type,
        "model": self.device_type,
        "subdevice_no": str(self.sub_device_no),
        "type": self.type,
        "cid": self.cid,
        "features:": self.features,
        "config_module": self.config_module,
        "connection_type": self.connection_type,
        "last_response": self.last_response,
    }
    state_dict = self.state.to_dict() if state else {}
    return device_dict | state_dict

to_json

to_json(state: bool = True, indent: bool = True) -> str

Inherited From VeSyncBaseDevice

Print JSON API string for device details.

Parameters:

Name Type Description Default
state bool

If True, include state in JSON output, defaults to True.

True
indent bool

If True, indent JSON output, defaults to True.

True

Returns:

Name Type Description
str str

JSON formatted string of device details.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def to_json(self, state: bool = True, indent: bool = True) -> str:
    """Print JSON API string for device details.

    Args:
        state (bool): If True, include state in JSON output, defaults to True.
        indent (bool): If True, indent JSON output, defaults to True.

    Returns:
        str: JSON formatted string of device details.
    """
    return self.to_jsonb(state, indent).decode()

to_jsonb

to_jsonb(state: bool = True, indent: bool = True) -> bytes

Inherited From VeSyncBaseDevice

JSON API bytes for device details.

Parameters:

Name Type Description Default
state bool

If True, include state in JSON output, defaults to True.

True
indent bool

If True, indent JSON output, defaults to True.

True

Returns:

Name Type Description
bytes bytes

JSON formatted bytes of device details.

Example

This is an example without state.

{
    "Device Name": "Living Room Lamp",
    "Model": "ESL100",
    "Subdevice No": "0",
    "Type": "wifi",
    "CID": "1234567890abcdef"
}

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def to_jsonb(self, state: bool = True, indent: bool = True) -> bytes:
    """JSON API bytes for device details.

    Args:
        state (bool): If True, include state in JSON output, defaults to True.
        indent (bool): If True, indent JSON output, defaults to True.

    Returns:
        bytes: JSON formatted bytes of device details.

    Example:
        This is an example without state.
        ```
        {
            "Device Name": "Living Room Lamp",
            "Model": "ESL100",
            "Subdevice No": "0",
            "Type": "wifi",
            "CID": "1234567890abcdef"
        }
        ```
    """
    return_dict = self.to_dict(state=state)
    if indent:
        return orjson.dumps(
            return_dict,
            option=orjson.OPT_INDENT_2 | orjson.OPT_NON_STR_KEYS,
        )

    return orjson.dumps(return_dict, option=orjson.OPT_NON_STR_KEYS)

toggle_switch abstractmethod async

toggle_switch(toggle: bool | None = None) -> bool

Inherited From VeSyncBaseToggleDevice

Toggle device power on or off.

Parameters:

Name Type Description Default
toggle bool | None

True to turn on, False to turn off, None to toggle.

None

Returns:

Name Type Description
bool bool

True if successful, False otherwise.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
@abstractmethod
async def toggle_switch(self, toggle: bool | None = None) -> bool:
    """Toggle device power on or off.

    Args:
        toggle (bool | None): True to turn on, False to turn off, None to toggle.

    Returns:
        bool: True if successful, False otherwise.
    """

turn_off async

turn_off() -> bool

Inherited From VeSyncBaseToggleDevice

Turn device off.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
async def turn_off(self) -> bool:
    """Turn device off."""
    return await self.toggle_switch(False)

turn_on async

turn_on() -> bool

Inherited From VeSyncBaseToggleDevice

Turn device on.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
async def turn_on(self) -> bool:
    """Turn device on."""
    return await self.toggle_switch(True)

update async

update() -> None

Inherited From VeSyncBaseDevice

Update device details.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
async def update(self) -> None:
    """Update device details."""
    await self.get_details()

VeSyncBaseDevice

VeSyncBaseDevice(
    details: ResponseDeviceDetailsModel,
    manager: VeSync,
    feature_map: DeviceMapTemplate,
)

Bases: ABC, Generic[VS_STATE_T]

Properties shared across all VeSync devices.

Abstract Base Class for all VeSync devices. The device class is used solely for operational methods and static device properties.

Parameters:

Name Type Description Default
details ResponseDeviceDetailsModel

Device details from API call.

required
manager VeSync

Manager object for API calls.

required
feature_map DeviceMapTemplate

Device configuration map, will be specific subclass of DeviceMapTemplate based on device type.

required

Attributes:

Name Type Description
state DeviceState

Device state object Each device has a separate state base class in the base_devices module.

last_response ResponseInfo

Last response from API call.

manager VeSync

Manager object for API calls.

device_name str

Name of device.

device_image str

URL for device image.

cid str

Device ID.

connection_type str

Connection type of device.

device_type str

Type of device.

type str

Type of device.

uuid str

UUID of device, not always present.

config_module str

Configuration module of device.

mac_id str

MAC ID of device.

current_firm_version str

Current firmware version of device.

device_region str

Region of device. (US, EU, etc.)

pid str

Product ID of device, pulled by some devices on update.

sub_device_no int

Sub-device number of device.

product_type str

Product type of device.

features dict

Features of device.

Methods:

Name Description
set_timer

Set timer for device.

get_timer

Get timer for device from API.

clear_timer

Clear timer for device from API.

set_state

Set device state attribute.

get_state

Get device state attribute.

update

Update device details.

display

Print formatted static device info to stdout.

to_json

Print JSON API string

to_jsonb

JSON API bytes device details

to_dict

Return device information as a dictionary.

Note

Device states are found in the state attribute in a subclass of DeviceState based on the device type. The DeviceState subclass is located in device the base_devices module.

The last_response attribute is used to store the last response and error information from the API call. See the pyvesync.errors module for more information.

Inherited From VeSyncBaseDevice

Initialize VeSync device base class.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def __init__(self,
             details: ResponseDeviceDetailsModel,
             manager: VeSync,
             feature_map: DeviceMapTemplate
             ) -> None:
    """Initialize VeSync device base class."""
    self._exclude_serialization: list[str] = []
    self.enabled: bool = True
    self.last_response: ResponseInfo | None = None
    self.manager = manager
    self.device_name: str = details.deviceName
    self.device_image: str | None = details.deviceImg
    self.cid: str = details.cid
    self.connection_type: str | None = details.connectionType
    self.device_type: str = details.deviceType
    self.type: str | None = details.type
    self.uuid: str | None = details.uuid
    self.config_module: str = details.configModule
    self.mac_id: str | None = details.macID
    self.current_firm_version = details.currentFirmVersion
    self.device_region: str | None = details.deviceRegion
    self.pid: str | None = None
    self.sub_device_no: int | None = details.subDeviceNo
    # From feature_map
    self.product_type: str = feature_map.product_type
    self.features: list[str] = feature_map.features

Attributes

cid instance-attribute

cid: str = cid

Inherited From VeSyncBaseDevice

config_module instance-attribute

config_module: str = configModule

Inherited From VeSyncBaseDevice

connection_type instance-attribute

connection_type: str | None = connectionType

Inherited From VeSyncBaseDevice

current_firm_version instance-attribute

current_firm_version = currentFirmVersion

Inherited From VeSyncBaseDevice

device_image instance-attribute

device_image: str | None = deviceImg

Inherited From VeSyncBaseDevice

device_name instance-attribute

device_name: str = deviceName

Inherited From VeSyncBaseDevice

device_region instance-attribute

device_region: str | None = deviceRegion

Inherited From VeSyncBaseDevice

device_type instance-attribute

device_type: str = deviceType

Inherited From VeSyncBaseDevice

enabled instance-attribute

enabled: bool = True

Inherited From VeSyncBaseDevice

features instance-attribute

features: list[str] = features

Inherited From VeSyncBaseDevice

firmware_update property

firmware_update: bool

Inherited From VeSyncBaseDevice

Return True if firmware update available.

This is going to be updated.

is_on property

is_on: bool

Inherited From VeSyncBaseDevice

Return true if device is on.

last_response instance-attribute

last_response: ResponseInfo | None = None

Inherited From VeSyncBaseDevice

mac_id instance-attribute

mac_id: str | None = macID

Inherited From VeSyncBaseDevice

manager instance-attribute

manager = manager

Inherited From VeSyncBaseDevice

product_type instance-attribute

product_type: str = product_type

Inherited From VeSyncBaseDevice

state instance-attribute

state: VS_STATE_T

Inherited From VeSyncBaseDevice

sub_device_no instance-attribute

sub_device_no: int | None = subDeviceNo

Inherited From VeSyncBaseDevice

type instance-attribute

type: str | None = type

Inherited From VeSyncBaseDevice

uuid instance-attribute

uuid: str | None = uuid

Inherited From VeSyncBaseDevice

Functions

clear_timer async

clear_timer() -> bool

Inherited From VeSyncBaseDevice

Clear timer for device from API.

This may not be implemented for all devices. Please open an issue if there is an error.

Returns:

Name Type Description
bool bool

True if successful, False otherwise.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
async def clear_timer(self) -> bool:
    """Clear timer for device from API.

    This may not be implemented for all devices. Please open an issue
    if there is an error.

    Returns:
        bool: True if successful, False otherwise.
    """
    logger.debug('Not implemented - clear_timer')
    return False

display

display(state: bool = True) -> None

Inherited From VeSyncBaseDevice

Print formatted static device info to stdout.

Parameters:

Name Type Description Default
state bool

If True, include state in display, defaults to True.

True

Example:

Device Name:..................Living Room Lamp
Model:........................ESL100
Subdevice No:.................0
Type:.........................wifi
CID:..........................1234567890abcdef

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def display(self, state: bool = True) -> None:
    """Print formatted static device info to stdout.

    Args:
        state (bool): If True, include state in display, defaults to True.

    Example:
    ```
    Device Name:..................Living Room Lamp
    Model:........................ESL100
    Subdevice No:.................0
    Type:.........................wifi
    CID:..........................1234567890abcdef
    ```
    """
    # noinspection SpellCheckingInspection
    display_list = [
        ('Device Name:', self.device_name),
        ('Product Type: ', self.product_type),
        ('Model: ', self.device_type),
        ('Subdevice No: ', str(self.sub_device_no)),
        ('Type: ', self.type),
        ('CID: ', self.cid),
        ('Config Module: ', self.config_module),
        ('Connection Type: ', self.connection_type),
        ('Features', self.features),
        ('Last Response: ', self.last_response),
    ]
    if self.uuid is not None:
        display_list.append(('UUID: ', self.uuid))

    for line in display_list:
        print(f'{line[0]:.<30} {line[1]}')
    if state:
        self.state.display()

get_details abstractmethod async

get_details() -> None

Inherited From VeSyncBaseDevice

Get device details.

This method is defined in each device class to contain the logic to pull the device state from the API and update the device's state attribute. The update() method should be called to update the device state.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
@abstractmethod
async def get_details(self) -> None:
    """Get device details.

    This method is defined in each device class to contain
    the logic to pull the device state from the API and update
    the device's `state` attribute. The `update()` method should
    be called to update the device state.
    """

get_state

get_state(state_attr: str) -> Any

Inherited From VeSyncBaseDevice

Get device state attribute.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def get_state(self, state_attr: str) -> Any:  # noqa: ANN401
    """Get device state attribute."""
    return getattr(self.state, state_attr)

get_timer async

get_timer() -> Timer | None

Inherited From VeSyncBaseDevice

Get timer for device from API and set the state.Timer attribute.

This may not be implemented for all devices. Please open an issue if there is an error.

Note

This method may not be implemented for all devices. Please open an issue if there is an error.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
async def get_timer(self) -> Timer | None:
    """Get timer for device from API and set the `state.Timer` attribute.

    This may not be implemented for all devices. Please open an issue
    if there is an error.

    Note:
        This method may not be implemented for all devices. Please
        open an issue if there is an error.
    """
    logger.debug('Not implemented - get_timer')
    return None

set_state

set_state(state_attr: str, stat_value: Any) -> None

Inherited From VeSyncBaseDevice

Set device state attribute.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def set_state(self, state_attr: str, stat_value: Any) -> None:  # noqa: ANN401
    """Set device state attribute."""
    setattr(self, state_attr, stat_value)

set_timer async

set_timer(duration: int, action: str | None = None) -> bool

Inherited From VeSyncBaseDevice

Set timer for device.

This may not be implemented for all devices. Please open an issue if there is an error.

Parameters:

Name Type Description Default
duration int

Duration in seconds.

required
action str | None

Action to take when timer expires.

None

Returns:

Name Type Description
bool bool

True if successful, False otherwise.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
async def set_timer(self, duration: int, action: str | None = None) -> bool:
    """Set timer for device.

    This may not be implemented for all devices. Please open an issue
    if there is an error.

    Args:
        duration (int): Duration in seconds.
        action (str | None): Action to take when timer expires.

    Returns:
        bool: True if successful, False otherwise.
    """
    del duration
    del action
    logger.debug('Not implemented - set_timer')
    return False

to_dict

to_dict(state: bool = True) -> dict[str, Any]

Inherited From VeSyncBaseDevice

Return device information as a dictionary.

Parameters:

Name Type Description Default
state bool

If True, include state in dictionary, defaults to True.

True

Returns:

Type Description
dict[str, Any]

dict[str, Any]: Dictionary containing device information.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def to_dict(self, state: bool = True) -> dict[str, Any]:
    """Return device information as a dictionary.

    Args:
        state (bool): If True, include state in dictionary, defaults to True.

    Returns:
        dict[str, Any]: Dictionary containing device information.
    """
    device_dict = {
        "device_name": self.device_name,
        "product_type": self.product_type,
        "model": self.device_type,
        "subdevice_no": str(self.sub_device_no),
        "type": self.type,
        "cid": self.cid,
        "features:": self.features,
        "config_module": self.config_module,
        "connection_type": self.connection_type,
        "last_response": self.last_response,
    }
    state_dict = self.state.to_dict() if state else {}
    return device_dict | state_dict

to_json

to_json(state: bool = True, indent: bool = True) -> str

Inherited From VeSyncBaseDevice

Print JSON API string for device details.

Parameters:

Name Type Description Default
state bool

If True, include state in JSON output, defaults to True.

True
indent bool

If True, indent JSON output, defaults to True.

True

Returns:

Name Type Description
str str

JSON formatted string of device details.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def to_json(self, state: bool = True, indent: bool = True) -> str:
    """Print JSON API string for device details.

    Args:
        state (bool): If True, include state in JSON output, defaults to True.
        indent (bool): If True, indent JSON output, defaults to True.

    Returns:
        str: JSON formatted string of device details.
    """
    return self.to_jsonb(state, indent).decode()

to_jsonb

to_jsonb(state: bool = True, indent: bool = True) -> bytes

Inherited From VeSyncBaseDevice

JSON API bytes for device details.

Parameters:

Name Type Description Default
state bool

If True, include state in JSON output, defaults to True.

True
indent bool

If True, indent JSON output, defaults to True.

True

Returns:

Name Type Description
bytes bytes

JSON formatted bytes of device details.

Example

This is an example without state.

{
    "Device Name": "Living Room Lamp",
    "Model": "ESL100",
    "Subdevice No": "0",
    "Type": "wifi",
    "CID": "1234567890abcdef"
}

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def to_jsonb(self, state: bool = True, indent: bool = True) -> bytes:
    """JSON API bytes for device details.

    Args:
        state (bool): If True, include state in JSON output, defaults to True.
        indent (bool): If True, indent JSON output, defaults to True.

    Returns:
        bytes: JSON formatted bytes of device details.

    Example:
        This is an example without state.
        ```
        {
            "Device Name": "Living Room Lamp",
            "Model": "ESL100",
            "Subdevice No": "0",
            "Type": "wifi",
            "CID": "1234567890abcdef"
        }
        ```
    """
    return_dict = self.to_dict(state=state)
    if indent:
        return orjson.dumps(
            return_dict,
            option=orjson.OPT_INDENT_2 | orjson.OPT_NON_STR_KEYS,
        )

    return orjson.dumps(return_dict, option=orjson.OPT_NON_STR_KEYS)

update async

update() -> None

Inherited From VeSyncBaseDevice

Update device details.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
async def update(self) -> None:
    """Update device details."""
    await self.get_details()

DeviceState

DeviceState(
    device: VeSyncBaseDevice,
    details: ResponseDeviceDetailsModel,
    feature_map: DeviceMapTemplate,
)

Base dataclass to hold device state.

Parameters:

Name Type Description Default
device VeSyncBaseDevice

Device object.

required
details ResponseDeviceDetailsModel

Device details from API call.

required
feature_map DeviceMapTemplate

Device configuration map, will be specific subclass of DeviceMapTemplate based on device type.

required

Attributes:

Name Type Description
active_time int

Active time of device, defaults to None.

connection_status str

Connection status of device.

device VeSyncBaseDevice

Device object.

device_status str

Device status.

features dict

Features of device.

last_update_ts int

Last update timestamp of device, defaults to None.

Methods:

Name Description
update_ts

Update last update timestamp.

to_dict

Dump state to JSON.

to_json

Dump state to JSON string.

to_jsonb

Dump state to JSON bytes.

as_tuple

Convert state to tuple of (name, value) tuples.

Note

This cannot be instantiated directly. It should be inherited by the state class of a specific product type.

Initialize device state.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def __init__(
    self,
    device: VeSyncBaseDevice,
    details: ResponseDeviceDetailsModel,
    feature_map: DeviceMapTemplate
        ) -> None:
    """Initialize device state."""
    self.__base_exclusions: list[str] = ['manager', 'device', 'state']
    self._exclude_serialization: list[str] = []
    self.device = device
    self.device_status: str = details.deviceStatus or DeviceStatus.UNKNOWN
    self.connection_status: str = details.connectionStatus or ConnectionStatus.UNKNOWN
    self.features = feature_map.features
    self.last_update_ts: int | None = None
    self.active_time: int | None = None
    self.timer: Timer | None = None

Attributes

active_time instance-attribute

active_time: int | None = None

Inherited From DeviceState

connection_status instance-attribute

connection_status: str = connectionStatus or UNKNOWN

Inherited From DeviceState

device instance-attribute

device = device

Inherited From DeviceState

device_status instance-attribute

device_status: str = deviceStatus or UNKNOWN

Inherited From DeviceState

features instance-attribute

features = features

Inherited From DeviceState

last_update_ts instance-attribute

last_update_ts: int | None = None

Inherited From DeviceState

timer instance-attribute

timer: Timer | None = None

Inherited From DeviceState

Functions

as_tuple

as_tuple() -> tuple[tuple[str, Any], ...]

Inherited From DeviceState

Convert state to tuple of (name, value) tuples.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def as_tuple(self) -> tuple[tuple[str, Any], ...]:
    """Convert state to tuple of (name, value) tuples."""
    return tuple((k, v) for k, v in self._serialize().items())

display

display() -> None

Inherited From DeviceState

Print formatted state to stdout.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def display(self) -> None:
    """Print formatted state to stdout."""
    for name, val in self._serialize().items():
        print(f'{name:.<30} {val}')

to_dict

to_dict() -> dict[str, Any]

Inherited From DeviceState

Convert state to dictionary.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def to_dict(self) -> dict[str, Any]:
    """Convert state to dictionary."""
    return self._serialize()

to_json

to_json(indent: bool = False) -> str

Inherited From DeviceState

Dump state to JSON string.

Parameters:

Name Type Description Default
indent bool

If True, indent JSON output, defaults to False.

False

Returns:

Name Type Description
str str

JSON formatted string of device state.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def to_json(self, indent: bool = False) -> str:
    """Dump state to JSON string.

    Args:
        indent (bool): If True, indent JSON output, defaults to False.

    Returns:
        str: JSON formatted string of device state.
    """
    return self.to_jsonb(indent=indent).decode()

to_jsonb

to_jsonb(indent: bool = False) -> bytes

Inherited From DeviceState

Convert state to JSON bytes.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def to_jsonb(self, indent: bool = False) -> bytes:
    """Convert state to JSON bytes."""
    if indent:
        return orjson.dumps(
            self._serialize(), option=orjson.OPT_NON_STR_KEYS | orjson.OPT_INDENT_2
        )
    return orjson.dumps(self._serialize(), option=orjson.OPT_NON_STR_KEYS)

update_ts

update_ts() -> None

Inherited From DeviceState

Update last update timestamp.

Source code in src\pyvesync\base_devices\vesyncbasedevice.py
def update_ts(self) -> None:
    """Update last update timestamp."""
    self.last_update_ts = int(dt.now(
        tz=ZoneInfo(self.device.manager.time_zone)).timestamp())