Device Container↲
pyvesync.device_container ↲
Module to contain VeSync device instances.
Attributes:
Name | Type | Description |
---|---|---|
DeviceContainerInstance |
DeviceContainer
|
Singleton instance of the DeviceContainer
class. This is imported by the |
Classes:
Name | Description |
---|---|
DeviceContainer |
Container for VeSync device instances.
This class should not be instantiated directly. Use the |
_DeviceContainerBase |
Base class for VeSync device
container. Inherits from |
DeviceContainerInstance
module-attribute
↲
DeviceContainerInstance = DeviceContainer()
Singleton instance of the DeviceContainer class.
This attribute should be imported by the vesync
module and
not the DeviceContainer
class directly.
pyvesync.device_container.DeviceContainer ↲
Bases: _DeviceContainerBase
Container for VeSync device instances.
Warning
type: warning
This class should not be instantiated directly. Use the DeviceContainerInstance
instead.
The DeviceContainer
class is a container for VeSync device instances that
inherits behavior from MutableSet
. The container contains all VeSync devices
and is used to store and manage device instances. The container is a singleton
and is instantiated directly by the DeviceContainerInstance
in the
device_container
module and imported as needed.
Use the add_new_devices
class method to add devices from the device list model API response and
remove_stale_devices
to remove stale devices from the device list API response
model. The device list response model is built in the
VeSync.get_devices() method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sequence
|
Sequence[VeSyncBaseDevice] | None
|
A sequence of device instances to initialize the container with. Typically this is not used directly, defaults to None. |
None
|
Attributes:
Name | Type | Description |
---|---|---|
_data |
set[VeSyncBaseDevice]
|
The mutable set of devices in the container. |
Source code in src\pyvesync\device_container.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
|
air_purifiers
property
↲
air_purifiers: list[VeSyncPurifier]
Return a list of devices that are air purifiers.
humidifiers
property
↲
humidifiers: list[VeSyncHumidifier]
Return a list of devices that are humidifiers.
thermostats
property
↲
thermostats: list[VeSyncThermostat]
Return a list of devices that are thermostats.
__init__ ↲
__init__(
sequence: Sequence[VeSyncBaseDevice] | None = None,
) -> None
Inherited From _DeviceContainerBase
Initialize the DeviceContainer class.
Initialize the DeviceContainer class.
_build_device_instance ↲
_build_device_instance(
device: ResponseDeviceDetailsModel, manager: VeSync
) -> VeSyncBaseDevice | None
Create a device from a single device model from the device list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device
|
ResponseDeviceDetailsModel
|
The device details model from the device list response model. |
required |
manager
|
VeSync
|
The VeSync instance to pass to the device instance |
required |
Returns:
Name | Type | Description |
---|---|---|
VeSyncBaseDevice |
VeSyncBaseDevice | None
|
The device instance created from the device list response model. |
Raises:
Type | Description |
---|---|
VeSyncAPIResponseError
|
If the model is not an instance of
|
Source code in src\pyvesync\device_container.py
add_device_from_model ↲
add_device_from_model(
device: ResponseDeviceDetailsModel, manager: VeSync
) -> None
Add a single device from the device list response model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device
|
ResponseDeviceDetailsModel
|
The device details model from the device list response model. |
required |
manager
|
VeSync
|
The VeSync instance to pass to the device instance |
required |
Raises:
Type | Description |
---|---|
VeSyncAPIResponseError
|
If the model is not an instance of
|
Source code in src\pyvesync\device_container.py
device_exists ↲
Check if a device with the given cid & sub_dev_no exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cid
|
str
|
The cid of the device to check. |
required |
sub_device_no
|
int
|
The sub_device_no of the device to check, defaults to 0 for most devices. |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the device exists, False otherwise. |
Source code in src\pyvesync\device_container.py
get_by_name ↲
get_by_name(
name: str, fuzzy: bool = False
) -> VeSyncBaseDevice | None
Forgiving method to get a device by name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the device to get. |
required |
fuzzy
|
bool
|
Use a fuzzy match to find the device. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
VeSyncBaseDevice | None
|
VeSyncBaseDevice | None: The device instance if found, None otherwise. |
Note
Fuzzy matching removes all non-alphanumeric characters and makes the string lowercase. If there are multiple devices with the same name, the first one found will be returned (a set is unordered).
Source code in src\pyvesync\device_container.py
remove_by_cid ↲
Remove a device by cid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cid
|
str
|
The cid of the device to remove. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the device was removed, False otherwise. |
Source code in src\pyvesync\device_container.py
discard ↲
discard(value: VeSyncBaseDevice) -> None
Discard a device from the container.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
VeSyncBaseDevice
|
The device to discard. |
required |
remove_stale_devices ↲
remove_stale_devices(
device_list_result: ResponseDeviceListModel,
) -> None
Remove devices that are not in the provided list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_list_result
|
ResponseDeviceListModel
|
The device list response model
from the VeSync API. This is generated by the |
required |
Source code in src\pyvesync\device_container.py
add_new_devices ↲
add_new_devices(
device_list_result: ResponseDeviceListModel,
manager: VeSync,
) -> None
Add new devices to the container.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device_list_result
|
ResponseDeviceListModel
|
The device list response model
from the VeSync API. This is generated by the |
required |
manager
|
VeSync
|
The VeSync instance to pass to the device instance |
required |
Source code in src\pyvesync\device_container.py
pyvesync.device_container._DeviceContainerBase ↲
Bases: MutableSet[VeSyncBaseDevice]
Base class for VeSync device container.
Inherits from MutableSet
and defines the core MutableSet methods.
Source code in src\pyvesync\device_container.py
__init__ ↲
__init__(
sequence: Sequence[VeSyncBaseDevice] | None = None,
) -> None
Initialize the DeviceContainer class.
Source code in src\pyvesync\device_container.py
__iter__ ↲
__iter__() -> Iterator[VeSyncBaseDevice]
Inherited From _DeviceContainerBase
Iterate over the container.
__len__ ↲
Inherited From _DeviceContainerBase
Return the length of the container.
add ↲
add(value: VeSyncBaseDevice) -> None
Inherited From _DeviceContainerBase
Add a device to the container.
remove ↲
remove(value: VeSyncBaseDevice) -> None
Inherited From _DeviceContainerBase
Remove a device from the container.
clear ↲
Inherited From _DeviceContainerBase
Clear the container.
__contains__ ↲
Inherited From _DeviceContainerBase
Check if a device is in the container.