Nicer config entry names
This commit is contained in:
parent
8797b119f2
commit
b241bf10b0
@ -47,10 +47,14 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
hass.data.setdefault(DOMAIN, {}).update(
|
hass.data.setdefault(DOMAIN, {}).update(
|
||||||
{
|
{
|
||||||
"stopping": False,
|
"stopping": False,
|
||||||
"manager": plejdManager,
|
|
||||||
"devices": devices,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
hass.data[DOMAIN].setdefault("devices", {}).update({
|
||||||
|
config_entry.entry_id: devices
|
||||||
|
})
|
||||||
|
hass.data[DOMAIN].setdefault("manager", {}).update({
|
||||||
|
config_entry.entry_id: plejdManager,
|
||||||
|
})
|
||||||
|
|
||||||
# Close any stale connections that may be open
|
# Close any stale connections that may be open
|
||||||
for dev in devices.values():
|
for dev in devices.values():
|
||||||
|
@ -28,22 +28,21 @@ class PlejdConfigFlow(ConfigFlow, domain="plejd"):
|
|||||||
async def async_step_picksite(self, info=None):
|
async def async_step_picksite(self, info=None):
|
||||||
if info is None:
|
if info is None:
|
||||||
sites = await api.get_sites(self.credentials["username"], self.credentials["password"])
|
sites = await api.get_sites(self.credentials["username"], self.credentials["password"])
|
||||||
|
self.sites = {site["site"]["siteId"]: site["site"]["title"] for site in sites}
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="picksite",
|
step_id="picksite",
|
||||||
data_schema=vol.Schema(
|
data_schema=vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required("site"): vol.In(
|
vol.Required("site"): vol.In(self.sites)
|
||||||
{
|
|
||||||
site["site"]["siteId"]: site["site"]["title"]
|
|
||||||
for site in sites
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
siteTitle = self.sites[info["site"]]
|
||||||
data={
|
data={
|
||||||
"username": self.credentials["username"],
|
"username": self.credentials["username"],
|
||||||
"password": self.credentials["password"],
|
"password": self.credentials["password"],
|
||||||
"siteId": info["site"]
|
"siteId": info["site"],
|
||||||
|
"siteTitle": siteTitle,
|
||||||
}
|
}
|
||||||
return self.async_create_entry(title="Plejd", data=data)
|
return self.async_create_entry(title=siteTitle, data=data)
|
||||||
|
@ -9,7 +9,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
DOMAIN = "plejd"
|
DOMAIN = "plejd"
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
devices = hass.data[DOMAIN]["devices"]
|
devices = hass.data[DOMAIN]["devices"].get(config_entry.entry_id, [])
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
for d in devices:
|
for d in devices:
|
||||||
|
@ -44,7 +44,7 @@ async def _get_site_details(session, siteId):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
site_data = {}
|
site_data = {}
|
||||||
async def get_site_data(username, password, siteId):
|
async def get_site_data(username, password, siteId, **_):
|
||||||
global site_data
|
global site_data
|
||||||
if site_data.get(siteId) is not None:
|
if site_data.get(siteId) is not None:
|
||||||
return site_data.get(siteId)
|
return site_data.get(siteId)
|
||||||
@ -55,7 +55,7 @@ async def get_site_data(username, password, siteId):
|
|||||||
site_data[siteId] = details
|
site_data[siteId] = details
|
||||||
return details
|
return details
|
||||||
|
|
||||||
async def get_sites(username, password):
|
async def get_sites(username, password, **_):
|
||||||
async with ClientSession(base_url=API_BASE_URL, headers=headers) as session:
|
async with ClientSession(base_url=API_BASE_URL, headers=headers) as session:
|
||||||
session_token = await _login(session, username, password)
|
session_token = await _login(session, username, password)
|
||||||
session.headers["X-Parse-Session-Token"] = session_token
|
session.headers["X-Parse-Session-Token"] = session_token
|
||||||
|
@ -25,7 +25,10 @@ class PlejdMesh():
|
|||||||
self.statecallback = None
|
self.statecallback = None
|
||||||
|
|
||||||
def add_mesh_node(self, device):
|
def add_mesh_node(self, device):
|
||||||
|
if device not in self.mesh_nodes:
|
||||||
self.mesh_nodes.append(device)
|
self.mesh_nodes.append(device)
|
||||||
|
else:
|
||||||
|
_LOGGER.debug("Plejd already added")
|
||||||
|
|
||||||
def set_crypto_key(self, key):
|
def set_crypto_key(self, key):
|
||||||
self.crypto_key = binascii.a2b_hex(key.replace("-", ""))
|
self.crypto_key = binascii.a2b_hex(key.replace("-", ""))
|
||||||
@ -71,7 +74,7 @@ class PlejdMesh():
|
|||||||
self.client = client
|
self.client = client
|
||||||
_LOGGER.debug("Connected to Plejd mesh")
|
_LOGGER.debug("Connected to Plejd mesh")
|
||||||
await asyncio.sleep(2)
|
await asyncio.sleep(2)
|
||||||
if not await self._authenticate() or not await self.ping():
|
if not await self._authenticate():
|
||||||
await self.client.disconnect()
|
await self.client.disconnect()
|
||||||
self._connected = False
|
self._connected = False
|
||||||
continue
|
continue
|
||||||
@ -164,6 +167,9 @@ class PlejdMesh():
|
|||||||
challenge = await self.client.read_gatt_char(PLEJD_AUTH)
|
challenge = await self.client.read_gatt_char(PLEJD_AUTH)
|
||||||
response = auth_response(self.crypto_key, challenge)
|
response = auth_response(self.crypto_key, challenge)
|
||||||
await self.client.write_gatt_char(PLEJD_AUTH, response, response=True)
|
await self.client.write_gatt_char(PLEJD_AUTH, response, response=True)
|
||||||
|
if not await self.ping():
|
||||||
|
_LOGGER.debug("Authenticion failed")
|
||||||
|
return False
|
||||||
_LOGGER.debug("Authenticated successfully")
|
_LOGGER.debug("Authenticated successfully")
|
||||||
return True
|
return True
|
||||||
except (BleakError, asyncio.TimeoutError) as e:
|
except (BleakError, asyncio.TimeoutError) as e:
|
||||||
|
@ -9,7 +9,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
DOMAIN = "plejd"
|
DOMAIN = "plejd"
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
devices = hass.data[DOMAIN]["devices"]
|
devices = hass.data[DOMAIN]["devices"].get(config_entry.entry_id, [])
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
for d in devices:
|
for d in devices:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user