Skip to content

Commit 91762e0

Browse files
add redir sensors
1 parent 97bd696 commit 91762e0

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

custom_components/npm_switches/sensor.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ async def async_setup_entry(hass, entry, async_add_entities):
1111
"""Setup sensor platform."""
1212
coordinator = hass.data[DOMAIN][entry.entry_id]
1313
entities = []
14-
entities.append(NpmSwitchesSensor(coordinator, entry, "enabled"))
15-
entities.append(NpmSwitchesSensor(coordinator, entry, "disabled"))
14+
entities.append(NpmSwitchesProxySensor(coordinator, entry, "enabled"))
15+
entities.append(NpmSwitchesProxySensor(coordinator, entry, "disabled"))
16+
entities.append(NpmSwitchesRedirSensor(coordinator, entry, "enabled"))
17+
entities.append(NpmSwitchesRedirSensor(coordinator, entry, "disabled"))
1618

1719
async_add_entities(entities, True)
1820

1921

20-
class NpmSwitchesSensor(NpmSwitchesEntity, SensorEntity):
21-
"""integration_blueprint Sensor class."""
22+
class NpmSwitchesProxySensor(NpmSwitchesEntity, SensorEntity):
23+
"""NPM Switches Proxy Sensor class."""
2224

2325
def __init__(
2426
self,
@@ -42,10 +44,43 @@ def __init__(
4244
def native_value(self):
4345
"""Return the native value of the sensor."""
4446
if self.sensor_name == "enabled":
45-
return self.coordinator.api.num_enabled
46-
return self.coordinator.api.num_disabled
47+
return self.coordinator.api.num_proxy_enabled
48+
return self.coordinator.api.num_proxy_disabled
4749

4850
@property
4951
def icon(self):
5052
"""Return the icon of the sensor."""
5153
return self._attr_icon
54+
55+
class NpmSwitchesRedirSensor(NpmSwitchesEntity, SensorEntity):
56+
"""NPM Switches Redir Sensor class."""
57+
58+
def __init__(
59+
self,
60+
coordinator: NpmSwitchesUpdateCoordinator,
61+
entry: ConfigEntry,
62+
name: str,
63+
) -> None:
64+
"""Initialize proxy switch entity."""
65+
super().__init__(coordinator, entry)
66+
self.proxy_id = name # Unique ID relies on self.proxy_id
67+
self.sensor_name = self.proxy_id
68+
self._attr_icon = "mdi:steering"
69+
self.friendly_name = "NPM " + self.sensor_name.capitalize() + " Redirection Hosts"
70+
71+
# @property
72+
# def name(self):
73+
# """Return the name of the sensor."""
74+
# return "npm_" + self.sensor_name + "_proxy_hosts"
75+
76+
@property
77+
def native_value(self):
78+
"""Return the native value of the sensor."""
79+
if self.sensor_name == "enabled":
80+
return self.coordinator.api.num_redir_enabled
81+
return self.coordinator.api.num_redir_disabled
82+
83+
@property
84+
def icon(self):
85+
"""Return the icon of the sensor."""
86+
return self._attr_icon

0 commit comments

Comments
 (0)