diff --git a/custom_components/meshtastic/aiomeshtastic/packet.py b/custom_components/meshtastic/aiomeshtastic/packet.py index 86c6284..f0b975f 100644 --- a/custom_components/meshtastic/aiomeshtastic/packet.py +++ b/custom_components/meshtastic/aiomeshtastic/packet.py @@ -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 diff --git a/custom_components/meshtastic/api.py b/custom_components/meshtastic/api.py index 9531b56..ec20e21 100644 --- a/custom_components/meshtastic/api.py +++ b/custom_components/meshtastic/api.py @@ -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, }, ) diff --git a/custom_components/meshtastic/const.py b/custom_components/meshtastic/const.py index 7ae1ec9..7040bd9 100644 --- a/custom_components/meshtastic/const.py +++ b/custom_components/meshtastic/const.py @@ -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 @@ -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") diff --git a/custom_components/meshtastic/logbook.py b/custom_components/meshtastic/logbook.py index 230225b..c0272e9 100644 --- a/custom_components/meshtastic/logbook.py +++ b/custom_components/meshtastic/logbook.py @@ -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, @@ -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})" @@ -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) @@ -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 = { @@ -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(