Statistics
About Statistics
Since PyPlumIO v0.5.56, you can access statistics via following property.
- AsyncProtocol.statistics
Return the statistics.
Statistics contain transfer data consisting of number of received/sent frames and bytes as well as datetime of when connection was established, when connection was lost and number of connection loss event.
- class pyplumio.protocol.Statistics(received_bytes: int = 0, received_frames: int = 0, sent_bytes: int = 0, sent_frames: int = 0, failed_frames: int = 0, connected_since: ~datetime.datetime | ~typing.Literal['never'] = 'never', connection_loss_at: ~datetime.datetime | ~typing.Literal['never'] = 'never', connection_losses: int = 0, devices: list[~pyplumio.protocol.DeviceStatistics] = <factory>)
Represents a connection statistics.
- Parameters:
received_bytes (int) – Number of received bytes. Resets on reconnect.
received_frames (int) – Number of received frames. Resets on reconnect.
sent_bytes (int) – Number of sent bytes. Resets on reconnect.
sent_frames (int) – Number of sent frames. Resets on reconnect.
failed_frames (int) – Number of failed frames. Resets on reconnect.
connected_since (datetime.datetime | Literal["never"]) – Datetime object representing connection time.
connection_loss_at (datetime.datetime | Literal["never"]) – Datetime object representing last connection loss event.
connection_losses (int) – Number of connection lost event.
devices (list[DeviceStatistics]) – Contains list of statistics for connected devices.
The devices property of statistics class of also contains a list of device statistics objects. Those statistics include time the device was initially connected as well as time, when device was last seen (sent an RegulatorData message).
- class pyplumio.protocol.DeviceStatistics(name: str, connected_since: datetime | Literal['never'] = 'never', last_seen: datetime | Literal['never'] = 'never')
Represents a device statistics.
- Parameters:
name (str) – Device name.
connected_since (datetime.datetime | Literal["never"]) – Datetime object representing connection time.
last_seen (datetime.datetime | Literal["never"]) – Datetime object representing time when device was last seen.
Statistics Examples
You can easily access statistic object via proxy call through Connection object as in example below.
import asyncio
import pyplumio
async def main():
"""Read the current heating temperature."""
async with pyplumio.open_tcp_connection("localhost", 8899) as conn:
print(conn.statistics)
asyncio.run(main())