11"""Switch platform for integration_blueprint."""
22import logging
3- from homeassistant .components .switch import SwitchEntity
3+ from homeassistant .components .switch import SwitchEntity , SwitchEntityDescription
4+ from homeassistant .util import slugify
45
56# from homeassistant.core import HomeAssistant
67from homeassistant .config_entries import ConfigEntry
@@ -51,11 +52,11 @@ def __init__(
5152 """Initialize proxy switch entity."""
5253 super ().__init__ (coordinator , entry )
5354 self .host = host
55+ self .name = "Proxy " + self .host ["domain_names" ][0 ].replace ("." , " " ).capitalize ()
56+ self .entity_id = "switch." + slugify (f"{ entry .title } { self .name } " )
57+ self ._attr_unique_id = f"{ entry .entry_id } { self .name } "
5458 self .host_id = str (host ["id" ])
5559 self .host_type = "proxy-hosts"
56- self .friendly_name = (
57- "NPM Proxy " + self .host ["domain_names" ][0 ].replace ("." , " " ).capitalize ()
58- )
5960
6061 async def async_turn_on (self , ** kwargs ): # pylint: disable=unused-argument
6162 """Turn on the switch."""
@@ -106,11 +107,11 @@ def __init__(
106107 """Initialize redir switch entity."""
107108 super ().__init__ (coordinator , entry )
108109 self .host = host
110+ self .name = "Redirect " + self .host ["domain_names" ][0 ].replace ("." , " " ).capitalize ()
111+ self .entity_id = "switch." + slugify (f"{ entry .title } { self .name } " )
112+ self ._attr_unique_id = f"{ entry .entry_id } { self .name } "
109113 self .host_type = "redirection-hosts"
110114 self .host_id = str (host ["id" ])
111- self .friendly_name = (
112- "NPM Redir " + self .host ["domain_names" ][0 ].replace ("." , " " ).capitalize ()
113- )
114115
115116 async def async_turn_on (self , ** kwargs ): # pylint: disable=unused-argument
116117 """Turn on the switch."""
@@ -124,11 +125,6 @@ async def async_turn_off(self, **kwargs): # pylint: disable=unused-argument
124125 self .async_write_ha_state ()
125126 self .host = await self .coordinator .api .get_host (self .host_id , self .host_type )
126127
127- # @property
128- # def name(self):
129- # """Return the name of the switch."""
130- # return "NPM " + self.host["domain_names"][0].replace(".", " ").capitalize()
131-
132128 @property
133129 def icon (self ):
134130 """Return the icon of this switch."""
@@ -162,11 +158,11 @@ def __init__(
162158 """Initialize steam switch entity."""
163159 super ().__init__ (coordinator , entry )
164160 self .host = host
161+ self .name = "Stream " + str (self .host ["incoming_port" ])
162+ self .entity_id = "switch." + slugify (f"{ entry .title } { self .name } " )
163+ self ._attr_unique_id = f"{ entry .entry_id } { self .name } "
165164 self .host_type = "streams"
166165 self .host_id = str (host ["id" ])
167- self .friendly_name = (
168- "NPM Stream " + str (self .host ["incoming_port" ])
169- )
170166
171167 async def async_turn_on (self , ** kwargs ): # pylint: disable=unused-argument
172168 """Turn on the switch."""
@@ -180,11 +176,6 @@ async def async_turn_off(self, **kwargs): # pylint: disable=unused-argument
180176 self .async_write_ha_state ()
181177 self .host = await self .coordinator .api .get_host (self .host_id , self .host_type )
182178
183- # @property
184- # def name(self):
185- # """Return the name of the switch."""
186- # return "NPM " + self.host["domain_names"][0].replace(".", " ").capitalize()
187-
188179 @property
189180 def icon (self ):
190181 """Return the icon of this switch."""
@@ -219,11 +210,11 @@ def __init__(
219210 """Initialize redir switch entity."""
220211 super ().__init__ (coordinator , entry )
221212 self .host = host
213+ self .name = "404 " + self .host ["domain_names" ][0 ].replace ("." , " " ).capitalize ()
214+ self .entity_id = "switch." + slugify (f"{ entry .title } { self .name } " )
215+ self ._attr_unique_id = f"{ entry .entry_id } { self .name } "
222216 self .host_type = "dead-hosts"
223217 self .host_id = str (host ["id" ])
224- self .friendly_name = (
225- "NPM Dead " + self .host ["domain_names" ][0 ].replace ("." , " " ).capitalize ()
226- )
227218
228219 async def async_turn_on (self , ** kwargs ): # pylint: disable=unused-argument
229220 """Turn on the switch."""
@@ -237,11 +228,6 @@ async def async_turn_off(self, **kwargs): # pylint: disable=unused-argument
237228 self .async_write_ha_state ()
238229 self .host = await self .coordinator .api .get_host (self .host_id , self .host_type )
239230
240- # @property
241- # def name(self):
242- # """Return the name of the switch."""
243- # return "NPM " + self.host["domain_names"][0].replace(".", " ").capitalize()
244-
245231 @property
246232 def icon (self ):
247233 """Return the icon of this switch."""
0 commit comments