@@ -18,12 +18,12 @@ async def async_setup_entry(hass, entry, async_add_entities):
1818 if entry .data ["include_redirection_hosts" ]:
1919 entities .append (NpmSwitchesRedirSensor (coordinator , entry , "enabled" ))
2020 entities .append (NpmSwitchesRedirSensor (coordinator , entry , "disabled" ))
21- # if entry.data["include_stream_hosts"]:
22- # entities.append(NpmSwitchesStreamSensor(coordinator, entry, "enabled"))
23- # entities.append(NpmSwitchesStreamSensor(coordinator, entry, "disabled"))
24- # if entry.data["include_dead_hosts"]:
25- # entities.append(NpmSwitchesDeadSensor(coordinator, entry, "enabled"))
26- # entities.append(NpmSwitchesDeadSensor(coordinator, entry, "disabled"))
21+ if entry .data ["include_stream_hosts" ]:
22+ entities .append (NpmSwitchesStreamSensor (coordinator , entry , "enabled" ))
23+ entities .append (NpmSwitchesStreamSensor (coordinator , entry , "disabled" ))
24+ if entry .data ["include_dead_hosts" ]:
25+ entities .append (NpmSwitchesDeadSensor (coordinator , entry , "enabled" ))
26+ entities .append (NpmSwitchesDeadSensor (coordinator , entry , "disabled" ))
2727
2828 async_add_entities (entities , True )
2929
@@ -71,8 +71,8 @@ def __init__(
7171 ) -> None :
7272 """Initialize proxy switch entity."""
7373 super ().__init__ (coordinator , entry )
74- self .redir_id = name # Unique ID relies on self.redir_id
75- self .sensor_name = self .redir_id
74+ self .host_id = name # Unique ID relies on self.host_id
75+ self .sensor_name = self .host_id
7676 self .friendly_name = "NPM Redirection Hosts " + self .sensor_name .capitalize ()
7777
7878 # @property
@@ -87,6 +87,70 @@ def native_value(self):
8787 return self .coordinator .api .num_redir_enabled
8888 return self .coordinator .api .num_redir_disabled
8989
90+ @property
91+ def icon (self ):
92+ """Return the icon of the sensor."""
93+ return "mdi:counter"
94+
95+ class NpmSwitchesStreamSensor (NpmSwitchesEntity , SensorEntity ):
96+ """NPM Switches Stream Sensor class."""
97+
98+ def __init__ (
99+ self ,
100+ coordinator : NpmSwitchesUpdateCoordinator ,
101+ entry : ConfigEntry ,
102+ name : str ,
103+ ) -> None :
104+ """Initialize proxy switch entity."""
105+ super ().__init__ (coordinator , entry )
106+ self .host_id = name # Unique ID relies on self.host_id
107+ self .sensor_name = self .host_id
108+ self .friendly_name = "NPM Steam Hosts " + self .sensor_name .capitalize ()
109+
110+ # @property
111+ # def name(self):
112+ # """Return the name of the sensor."""
113+ # return "npm_" + self.sensor_name + "_proxy_hosts"
114+
115+ @property
116+ def native_value (self ):
117+ """Return the native value of the sensor."""
118+ if self .sensor_name == "enabled" :
119+ return self .coordinator .api .num_stream_enabled
120+ return self .coordinator .api .num_stream_disabled
121+
122+ @property
123+ def icon (self ):
124+ """Return the icon of the sensor."""
125+ return "mdi:counter"
126+
127+ class NpmSwitchesDeadSensor (NpmSwitchesEntity , SensorEntity ):
128+ """NPM Switches Deam Sensor class."""
129+
130+ def __init__ (
131+ self ,
132+ coordinator : NpmSwitchesUpdateCoordinator ,
133+ entry : ConfigEntry ,
134+ name : str ,
135+ ) -> None :
136+ """Initialize proxy switch entity."""
137+ super ().__init__ (coordinator , entry )
138+ self .host_id = name # Unique ID relies on self.host_id
139+ self .sensor_name = self .host_id
140+ self .friendly_name = "NPM Dead Hosts " + self .sensor_name .capitalize ()
141+
142+ # @property
143+ # def name(self):
144+ # """Return the name of the sensor."""
145+ # return "npm_" + self.sensor_name + "_proxy_hosts"
146+
147+ @property
148+ def native_value (self ):
149+ """Return the native value of the sensor."""
150+ if self .sensor_name == "enabled" :
151+ return self .coordinator .api .num_dead_enabled
152+ return self .coordinator .api .num_dead_disabled
153+
90154 @property
91155 def icon (self ):
92156 """Return the icon of the sensor."""
0 commit comments