|
37 | 37 | CONF_API_PASSWORD = 'api_password' |
38 | 38 | CONF_SUBSCRIBE_EVENTS = 'subscribe_events' |
39 | 39 | CONF_ENTITY_PREFIX = 'entity_prefix' |
40 | | -CONF_STATE_ENTITY_NAME = 'state_entity_name' |
41 | 40 | CONF_FILTER = 'filter' |
42 | 41 |
|
43 | 42 | STATE_INIT = 'initializing' |
|
54 | 53 |
|
55 | 54 | INSTANCES_SCHEMA = vol.Schema({ |
56 | 55 | vol.Required(CONF_HOST): cv.string, |
57 | | - vol.Required(CONF_STATE_ENTITY_NAME): cv.string, |
58 | 56 | vol.Optional(CONF_PORT, default=8123): cv.port, |
59 | 57 | vol.Optional(CONF_SECURE, default=False): cv.boolean, |
60 | 58 | vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean, |
@@ -120,7 +118,6 @@ def __init__(self, hass, conf): |
120 | 118 | """Initialize the connection.""" |
121 | 119 | self._hass = hass |
122 | 120 | self._host = conf.get(CONF_HOST) |
123 | | - self._connection_state_entity = 'sensor.' + conf.get(CONF_STATE_ENTITY_NAME) |
124 | 121 | self._port = conf.get(CONF_PORT) |
125 | 122 | self._secure = conf.get(CONF_SECURE) |
126 | 123 | self._verify_ssl = conf.get(CONF_VERIFY_SSL) |
@@ -149,6 +146,13 @@ def __init__(self, hass, conf): |
149 | 146 | self._subscribe_events = conf.get(CONF_SUBSCRIBE_EVENTS) |
150 | 147 | self._entity_prefix = conf.get(CONF_ENTITY_PREFIX) |
151 | 148 |
|
| 149 | + self._connection_state_entity = 'sensor.' |
| 150 | + |
| 151 | + if self._entity_prefix != '': |
| 152 | + self._connection_state_entity = '{}{}'.format(self._connection_state_entity, self._entity_prefix) |
| 153 | + |
| 154 | + self._connection_state_entity = '{}remote_connection_{}_{}'.format(self._connection_state_entity, self._host.replace('.', '_').replace('-', '_'), self._port) |
| 155 | + |
152 | 156 | self._connection = None |
153 | 157 | self._entities = set() |
154 | 158 | self._handlers = {} |
@@ -234,8 +238,8 @@ async def _disconnected(self): |
234 | 238 | self._hass.states.async_remove(entity) |
235 | 239 | if self._remove_listener is not None: |
236 | 240 | self._remove_listener() |
237 | | - if self._connection_state_entity is not None: |
238 | | - self._hass.states.async_set(self._connection_state_entity, STATE_DISCONNECTED) |
| 241 | + |
| 242 | + self._hass.states.async_set(self._connection_state_entity, STATE_DISCONNECTED) |
239 | 243 | self._remove_listener = None |
240 | 244 | self._entities = set() |
241 | 245 | asyncio.ensure_future(self.async_connect()) |
|
0 commit comments