Skip to content

Commit c101ca5

Browse files
committed
Reenable current readings, but hide them (and voltage) by default.
Note that this requires a fresh config directory as HomeAssistant doesn't actually forget entities even after they've been deleted.
1 parent afba842 commit c101ca5

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from enum import Enum
22

3-
43
class PlugMeasurements(Enum):
54
WATTS = 1
65
VOLTAGE = 2
76
APPARENT_CURRENT = 3
87
ACTIVE_CURRENT = 4
9-
REACTIVE_CURRENT =5
8+
REACTIVE_CURRENT = 5
109
SUMMATION_ENERGY = 6

custom_components/powersensor/PowersensorEntity.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def __init__(self, hass: HomeAssistant, mac : str,
4040
self._attr_native_unit_of_measurement = config["unit"]
4141
self._attr_device_info = self.device_info
4242
self._attr_suggested_display_precision = config["precision"]
43+
self._attr_entity_registry_visible_default = config['visible'] if 'visible' in config.keys() else True
44+
4345
self._signal = f"{POWER_SENSOR_UPDATE_SIGNAL}_{self._mac}_{config['event']}"
4446
if 'state_class' in config.keys():
4547
self._attr_state_class = config['state_class']

custom_components/powersensor/PowersensorPlugEntity.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
_LOGGER = logging.getLogger(__name__)
1313

1414

15-
1615
_config = {
1716
PlugMeasurements.WATTS: {
1817
"name": "Power",
@@ -28,31 +27,35 @@
2827
"unit": UnitOfElectricPotential.VOLT,
2928
"precision": 2,
3029
'event': 'average_power_components',
31-
'message_key': 'volts'
30+
'message_key': 'volts',
31+
'visible': False,
3232
},
3333
PlugMeasurements.APPARENT_CURRENT: {
3434
"name": "Apparent Current",
3535
"device_class": SensorDeviceClass.CURRENT,
3636
"unit": UnitOfElectricCurrent.AMPERE,
3737
"precision": 2,
3838
'event': 'average_power_components',
39-
'message_key': 'apparent_current'
39+
'message_key': 'apparent_current',
40+
'visible': False,
4041
},
4142
PlugMeasurements.ACTIVE_CURRENT: {
42-
"name": "Current", #"Active Current"
43+
"name": "Active Current",
4344
"device_class": SensorDeviceClass.CURRENT,
4445
"unit": UnitOfElectricCurrent.AMPERE,
4546
"precision": 2,
4647
'event': 'average_power_components',
47-
'message_key': 'active_current'
48+
'message_key': 'active_current',
49+
'visible': False,
4850
},
4951
PlugMeasurements.REACTIVE_CURRENT: {
5052
"name": "Reactive Current",
5153
"device_class": SensorDeviceClass.CURRENT,
5254
"unit": UnitOfElectricCurrent.AMPERE,
5355
"precision": 2,
5456
'event': 'average_power_components',
55-
'message_key': 'reactive_current'
57+
'message_key': 'reactive_current',
58+
'visible': False,
5659
},
5760
PlugMeasurements.SUMMATION_ENERGY: {
5861
"name": "Total Energy",
@@ -86,7 +89,6 @@ def device_info(self) -> DeviceInfo:
8689
'manufacturer': "Powersensor",
8790
'model': self._model,
8891
'name': self._device_name,
89-
# "via_device": # if we use this, can it be updated dynamically?
9092
}
9193

9294
def _default_device_name(self) -> str:

custom_components/powersensor/PowersensorSensorEntity.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def device_info(self) -> DeviceInfo:
6262
'manufacturer': "Powersensor",
6363
'model': self._model,
6464
'name': self._device_name ,
65-
# "via_device": # if we use this, can it be updated dynamically?
6665
}
6766

6867
def _ensure_matching_prefix(self):

custom_components/powersensor/sensor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ async def async_setup_entry(
3232
async def create_plug(plug_mac_address: str):
3333
this_plug_sensors = [PowersensorPlugEntity(hass, plug_mac_address, PlugMeasurements.WATTS),
3434
PowersensorPlugEntity(hass, plug_mac_address, PlugMeasurements.VOLTAGE),
35+
PowersensorPlugEntity(hass, plug_mac_address, PlugMeasurements.APPARENT_CURRENT),
3536
PowersensorPlugEntity(hass, plug_mac_address, PlugMeasurements.ACTIVE_CURRENT),
37+
PowersensorPlugEntity(hass, plug_mac_address, PlugMeasurements.REACTIVE_CURRENT),
3638
PowersensorPlugEntity(hass, plug_mac_address, PlugMeasurements.SUMMATION_ENERGY)]
3739

3840
async_add_entities(this_plug_sensors, True)

0 commit comments

Comments
 (0)