preheat_open.api.types.DeviceQuery

class preheat_open.api.types.DeviceQuery(exclude=None, id=<factory>, name=<factory>, type=<factory>)

Bases: Query

__init__(exclude=None, id=<factory>, name=<factory>, type=<factory>)

Methods

__init__([exclude, id, name, type])

convert_attr(value, name)

Convert an attribute value to the appropriate type.

from_kwargs([query])

Create a Query object from keyword arguments.

is_type(obj)

Check if an object is of the type this query is designed to filter.

isin(iterable)

Check if this query matches any element in an iterable.

Attributes

exclude

id

name

type

classmethod convert_attr(value, name)

Convert an attribute value to the appropriate type.

This method applies type conversion based on class-defined type hints or special type attributes. It supports both direct instantiation and dictionary-based construction.

Parameters:
  • value (Any) – The value to convert

  • name (str) – The attribute name for type lookup

Returns:

The converted value

Return type:

Any

Example:
>>> from dataclasses import field
>>> @dataclass(eq=False)
... class TestQuery(Query):
...     _type_age = int
...     _class = object
>>>
>>> converted = TestQuery.convert_attr("25", "age")
>>> converted
25
>>> isinstance(converted, int)
True
classmethod from_kwargs(query=None, **kwargs)

Create a Query object from keyword arguments.

This factory method creates a new Query instance from keyword arguments, with optional base query for inheritance. It validates that all provided keys are valid attributes for the query class.

Parameters:
  • query (Query, optional) – An existing Query object to use as a base

  • kwargs – Additional keyword arguments for query attributes

Returns:

A new Query object of the same type as the class

Return type:

QueryT

Raises:

TypeError – If unknown keys are provided in kwargs

Example:
>>> from dataclasses import field
>>> @dataclass(eq=False)
... class PersonQuery(Query):
...     name: list[str] = field(default_factory=list)
...     age: list[int] = field(default_factory=list)
...     _class = object
>>>
>>> query = PersonQuery.from_kwargs(name="Alice", age=30)
>>> type(query).__name__
'PersonQuery'
>>> query.name
['Alice']
>>> query.age
[30]
classmethod is_type(obj)

Check if an object is of the type this query is designed to filter.

This method uses a naming convention where the query class name ends with “Query” and the target class name is the prefix.

Parameters:

obj (object) – The object to check

Returns:

True if the object matches the expected type

Return type:

bool

Example:
>>> from dataclasses import field
>>> @dataclass(eq=False)
... class PersonQuery(Query):
...     _class = object
>>>
>>> class Person:
...     pass
>>>
>>> person = Person()
>>> PersonQuery.is_type(person)
True
isin(iterable)

Check if this query matches any element in an iterable.

This method iterates through the provided iterable and returns True if any element matches this query’s criteria.

Parameters:

iterable (Iterable) – The iterable to search through

Returns:

True if any element matches the query

Return type:

bool

Example:
>>> from dataclasses import field
>>> @dataclass
... class Person:
...     name: str
>>>
>>> @dataclass(eq=False)
... class PersonQuery(Query):
...     name: list[str] = field(default_factory=list)
...     _class = Person
>>>
>>> people = [Person("Alice"), Person("Bob"), Person("Charlie")]
>>> query = PersonQuery(name="Bob")
>>> query.isin(people)
True
>>>
>>> query2 = PersonQuery(name="David")
>>> query2.isin(people)
False