1
1
"""Switch platform for integration_blueprint."""
2
2
import logging
3
- from homeassistant .components .switch import SwitchEntity
3
+ from homeassistant .components .switch import SwitchEntity , SwitchEntityDescription
4
+ from homeassistant .util import slugify
4
5
5
6
# from homeassistant.core import HomeAssistant
6
7
from homeassistant .config_entries import ConfigEntry
@@ -51,11 +52,11 @@ def __init__(
51
52
"""Initialize proxy switch entity."""
52
53
super ().__init__ (coordinator , entry )
53
54
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 } "
54
58
self .host_id = str (host ["id" ])
55
59
self .host_type = "proxy-hosts"
56
- self .friendly_name = (
57
- "NPM Proxy " + self .host ["domain_names" ][0 ].replace ("." , " " ).capitalize ()
58
- )
59
60
60
61
async def async_turn_on (self , ** kwargs ): # pylint: disable=unused-argument
61
62
"""Turn on the switch."""
@@ -106,11 +107,11 @@ def __init__(
106
107
"""Initialize redir switch entity."""
107
108
super ().__init__ (coordinator , entry )
108
109
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 } "
109
113
self .host_type = "redirection-hosts"
110
114
self .host_id = str (host ["id" ])
111
- self .friendly_name = (
112
- "NPM Redir " + self .host ["domain_names" ][0 ].replace ("." , " " ).capitalize ()
113
- )
114
115
115
116
async def async_turn_on (self , ** kwargs ): # pylint: disable=unused-argument
116
117
"""Turn on the switch."""
@@ -124,11 +125,6 @@ async def async_turn_off(self, **kwargs): # pylint: disable=unused-argument
124
125
self .async_write_ha_state ()
125
126
self .host = await self .coordinator .api .get_host (self .host_id , self .host_type )
126
127
127
- # @property
128
- # def name(self):
129
- # """Return the name of the switch."""
130
- # return "NPM " + self.host["domain_names"][0].replace(".", " ").capitalize()
131
-
132
128
@property
133
129
def icon (self ):
134
130
"""Return the icon of this switch."""
@@ -162,11 +158,11 @@ def __init__(
162
158
"""Initialize steam switch entity."""
163
159
super ().__init__ (coordinator , entry )
164
160
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 } "
165
164
self .host_type = "streams"
166
165
self .host_id = str (host ["id" ])
167
- self .friendly_name = (
168
- "NPM Stream " + str (self .host ["incoming_port" ])
169
- )
170
166
171
167
async def async_turn_on (self , ** kwargs ): # pylint: disable=unused-argument
172
168
"""Turn on the switch."""
@@ -180,11 +176,6 @@ async def async_turn_off(self, **kwargs): # pylint: disable=unused-argument
180
176
self .async_write_ha_state ()
181
177
self .host = await self .coordinator .api .get_host (self .host_id , self .host_type )
182
178
183
- # @property
184
- # def name(self):
185
- # """Return the name of the switch."""
186
- # return "NPM " + self.host["domain_names"][0].replace(".", " ").capitalize()
187
-
188
179
@property
189
180
def icon (self ):
190
181
"""Return the icon of this switch."""
@@ -219,11 +210,11 @@ def __init__(
219
210
"""Initialize redir switch entity."""
220
211
super ().__init__ (coordinator , entry )
221
212
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 } "
222
216
self .host_type = "dead-hosts"
223
217
self .host_id = str (host ["id" ])
224
- self .friendly_name = (
225
- "NPM Dead " + self .host ["domain_names" ][0 ].replace ("." , " " ).capitalize ()
226
- )
227
218
228
219
async def async_turn_on (self , ** kwargs ): # pylint: disable=unused-argument
229
220
"""Turn on the switch."""
@@ -237,11 +228,6 @@ async def async_turn_off(self, **kwargs): # pylint: disable=unused-argument
237
228
self .async_write_ha_state ()
238
229
self .host = await self .coordinator .api .get_host (self .host_id , self .host_type )
239
230
240
- # @property
241
- # def name(self):
242
- # """Return the name of the switch."""
243
- # return "NPM " + self.host["domain_names"][0].replace(".", " ").capitalize()
244
-
245
231
@property
246
232
def icon (self ):
247
233
"""Return the icon of this switch."""
0 commit comments