Skip to content

Base

This module provides the base class for all items.

pyown.items.base.BaseItem

BaseItem(
    client: BaseClient,
    where: Where | str,
    *,
    who: Who | str | None = None
)

Bases: ABC

The base class for all items. This class provides the basic functionality to communicate with the server using the client.

client: The client to use to communicate with the server.
where: The location of the item.
who: The type of item.

where property

where: Where

Returns the where value of the item.

who classmethod property

who: Who

Returns the who value of the item.

client property writable

client: BaseClient

Returns the client used to communicate with the server.

call_callbacks abstractmethod async classmethod

call_callbacks(
    item: Self, message: BaseMessage
) -> list[Task]

Calls the registered callbacks for the event. Used internally by the client to dispatch the events to the correct callbacks.

Parameters:

Name Type Description Default
item BaseItem

The item that triggered the event.

required
message BaseMessage

The message that triggered the event.

required

Returns:

Type Description
list[Task]

list[Task]: A list of tasks scheduled to run the callbacks.

create_normal_message

create_normal_message(what: What | str) -> NormalMessage

Creates a normal message for the item. Args: what: The action to perform. Returns: A normal message.

create_status_message

create_status_message() -> StatusRequest

Creates a status message for the item.

Returns:

Type Description
StatusRequest

A status message.

create_dimension_writing_message

create_dimension_writing_message(
    dimension: Dimension, *args: Value
) -> DimensionWriting

Creates a dimension message for the item. Args: dimension: the dimension value to set. *args: the values to set.

Returns:

create_dimension_request_message

create_dimension_request_message(
    dimension: Dimension,
) -> DimensionRequest

Creates a dimension request message for the item. Args: dimension: the dimension value to request.

Returns:

send_normal_message async

send_normal_message(what: What | str) -> None

Sends a normal message to the server and check the response.

Parameters:

Name Type Description Default
what What | str

The action to perform.

required

Raises:

Type Description
ResponseError

If the server does not acknowledge the message.

send_status_request async

send_status_request() -> AsyncIterator[NormalMessage]

Sends a status request and receive multiple responses from the server.

Raises:

Type Description
ResponseError

If the server responds with an invalid message.

Returns:

Type Description
AsyncIterator[NormalMessage]

The responses from the server.

send_dimension_request async

send_dimension_request(
    dimension: Dimension | str,
) -> AsyncIterator[DimensionResponse]

Sends a dimension request and receive multiple responses from the server.

Raises:

Type Description
ResponseError

If the server responds with an invalid message.

Returns:

Type Description
AsyncIterator[DimensionResponse]

The responses from the server.

send_dimension_writing async

send_dimension_writing(
    dimension: Dimension | str, *args: Value
) -> None

Sends a dimension writing message to the server and check the response.

Parameters:

Name Type Description Default
dimension Dimension | str

the dimension value to set.

required
*args Value

the values to set.

()

Raises:

Type Description
ResponseError

If the server does not acknowledge the message.

pyown.items.base.CoroutineCallback module-attribute

CoroutineCallback = Callable[
    ..., Coroutine[None, None, None]
]

Type alias for a coroutine function that does not return anything.

pyown.items.base.EventMessage module-attribute

EventMessage = DimensionResponse | DimensionWriting | None

Type alias for the event messages that can be received by the item.

pyown.items.utils.ITEM_TYPES module-attribute

ITEM_TYPES: Final[dict[Who, Type[BaseItem]]] = {
    LIGHTING: Light,
    AUTOMATION: Automation,
    GATEWAY: Gateway,
}

A dictionary that maps the Who tag to the corresponding item class.