Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions custom_components/meshtastic/aiomeshtastic/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def rx_time(self) -> int | None:
def rx_snr(self) -> float | None:
return self.mesh_packet.rx_snr if self.mesh_packet is not None else None

@property
def rx_rssi(self) -> int | None:
return self.mesh_packet.rx_rssi if self.mesh_packet is not None else None

@property
def to_id(self) -> int | None:
return self.mesh_packet.to if self.mesh_packet is not None else None
Expand Down
2 changes: 2 additions & 0 deletions custom_components/meshtastic/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ async def _on_text_message(self, node: MeshNode, packet: Packet) -> None:
"to": {"node": to_node, "channel": to_channel},
"gateway": self.get_own_node()["num"],
"message": packet.app_payload,
"snr": packet.rx_snr,
"rssi": packet.rx_rssi,
},
)

Expand Down
6 changes: 4 additions & 2 deletions custom_components/meshtastic/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ class MeshtasticDomainEventData(TypedDict):
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_FROM_NAME: Final = "from_name"
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_PKI: Final = "pki"
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_MESSAGE: Final = "message"

EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_SNR: Final = "snr"
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_RSSI: Final = "rssi"

class MeshtasticDomainMessageLogEventData(TypedDict):
CONF_DEVICE_ID: str
Expand All @@ -114,7 +115,8 @@ class MeshtasticDomainMessageLogEventData(TypedDict):
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_FROM_NAME: str
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_PKI: bool
EVENT_MESHTASTIC_DOMAIN_EVENT_DATA_ATTR_MESSAGE: str

EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_SNR: float
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_RSSI: int

# Event used for logbook
EVENT_MESHTASTIC_DOMAIN_MESSAGE_LOG: EventType[MeshtasticDomainMessageLogEventData] = EventType(f"{DOMAIN}_message_log")
Expand Down
10 changes: 10 additions & 0 deletions custom_components/meshtastic/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_FROM_NAME,
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_MESSAGE,
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_PKI,
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_RSSI,
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_SNR,
MeshtasticDomainEventData,
MeshtasticDomainEventType,
MeshtasticDomainMessageLogEventData,
Expand Down Expand Up @@ -98,6 +100,8 @@ def _publish_message_log_event( # noqa: PLR0913
to_channel_entity_id: str,
to_dm_entity_id: str,
message: str,
snr: float,
rssi: int,
) -> None:
if (node_info := entry.runtime_data.client.get_node_info(int(from_node_id))) is not None:
from_name = f"{node_info.long_name} ({node_info.user_id})"
Expand All @@ -109,6 +113,8 @@ def _publish_message_log_event( # noqa: PLR0913
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_FROM_NAME: from_name,
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_PKI: bool(to_dm_entity_id),
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_MESSAGE: message,
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_SNR: snr,
EVENT_MESHTASTIC_MESSAGE_LOG_EVENT_DATA_ATTR_RSSI: rssi,
}
hass.bus.async_fire(event_type=EVENT_MESHTASTIC_DOMAIN_MESSAGE_LOG, event_data=message_log_event_data)

Expand All @@ -132,6 +138,8 @@ async def _on_text_message(event: Event) -> None:
config_entry_id, gateway_node_id, to, to_device
)
message = data["message"]
snr = data["snr"]
rssi = data["rssi"]

if from_device:
domain_event_data: MeshtasticDomainEventData = {
Expand Down Expand Up @@ -168,6 +176,8 @@ async def _on_text_message(event: Event) -> None:
to_channel_entity_id,
to_dm_entity_id,
message,
snr,
rssi,
)

def extract_device_and_entity_from_channel(
Expand Down