Skip to content

Commit 91d2852

Browse files
authored
Merge pull request #11 from DiUS/feature/rssi-diagnostic
Feature/rssi diagnostic
2 parents 77427dc + 65d8f64 commit 91d2852

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

custom_components/powersensor/PowersensorMessageDispatcher.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ def _create_api(self, mac_address, ip, port, name):
140140
self._known_plugs.add(mac_address)
141141
self._known_plug_names[name] = mac_address
142142
known_evs = [
143-
#'exception',
144143
'average_flow',
145144
'average_power',
146145
'average_power_components',
@@ -154,6 +153,7 @@ def _create_api(self, mac_address, ip, port, name):
154153
for ev in known_evs:
155154
api.subscribe(ev, self.handle_message)
156155
api.subscribe('now_relaying_for', self.handle_relaying_for)
156+
api.subscribe('exception', self.handle_exception)
157157
api.connect()
158158

159159
def cancel_any_pending_removal(self, mac, source):
@@ -162,6 +162,9 @@ def cancel_any_pending_removal(self, mac, source):
162162
task.cancel()
163163
_LOGGER.debug(f"Cancelled pending removal for {mac} by {source}.")
164164

165+
async def handle_exception(self, event: str, exc: BaseException):
166+
_LOGGER.error(f"Plug connection reported exception: {exc}")
167+
165168
async def handle_relaying_for(self, event: str, message: dict):
166169
"""Handle a potentially new sensor being reported."""
167170
mac = message.get('mac', None)

custom_components/powersensor/PowersensorSensorEntity.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
2-
from homeassistant.const import EntityCategory, UnitOfPower, UnitOfEnergy, PERCENTAGE
2+
from homeassistant.const import EntityCategory, UnitOfPower, UnitOfEnergy, PERCENTAGE, SIGNAL_STRENGTH_DECIBELS
33
from homeassistant.core import HomeAssistant
44
from homeassistant.helpers.device_registry import DeviceInfo
55

@@ -47,6 +47,15 @@
4747
'event': 'role',
4848
'message_key': 'role',
4949
},
50+
SensorMeasurements.RSSI: {
51+
'name': 'Signal strength (Bluetooth)',
52+
"device_class": SensorDeviceClass.SIGNAL_STRENGTH,
53+
"unit": SIGNAL_STRENGTH_DECIBELS,
54+
"precision": 1,
55+
'category': EntityCategory.DIAGNOSTIC,
56+
'event': 'radio_signal_quality',
57+
'message_key': 'average_rssi',
58+
},
5059
}
5160

5261
class PowersensorSensorEntity(PowersensorEntity):

custom_components/powersensor/SensorMeasurements.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ class SensorMeasurements(Enum):
66
WATTS = 2
77
SUMMATION_ENERGY = 3
88
ROLE = 4
9+
RSSI = 5

custom_components/powersensor/sensor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ async def handle_discovered_sensor(sensor_mac: str, sensor_role: str):
110110
PowersensorSensorEntity(hass, sensor_mac, sensor_role, SensorMeasurements.WATTS),
111111
PowersensorSensorEntity(hass, sensor_mac, sensor_role, SensorMeasurements.SUMMATION_ENERGY),
112112
PowersensorSensorEntity(hass, sensor_mac, sensor_role, SensorMeasurements.ROLE),
113+
PowersensorSensorEntity(hass, sensor_mac, sensor_role, SensorMeasurements.RSSI),
113114
]
114115
async_add_entities(new_sensors, True)
115116
async_dispatcher_send(hass, SENSOR_ADDED_TO_HA_SIGNAL, sensor_mac, sensor_role)

0 commit comments

Comments
 (0)