8000 Add Xiaomi Miio EU gateway support by starkillerOG · Pull Request #47955 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add Xiaomi Miio EU gateway support #47955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 62 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
91f4502
Add EU gateway support
starkillerOG Mar 15, 2021
9ccd753
add options flow translations
starkillerOG Mar 15, 2021
14ae84a
fix options flow
starkillerOG Mar 15, 2021
72d8414
fix missing import
starkillerOG Mar 15, 2021
208c0da
try to fix async_add_executor_job
starkillerOG Mar 15, 2021
b9234e6
try to fix async_add_executor_job
starkillerOG Mar 15, 2021
cd15685
fix unload
starkillerOG Mar 15, 2021
096bb33
check for login succes
starkillerOG Mar 15, 2021
941cfdf
fix not reloading
starkillerOG Mar 15, 2021
e5deb23
use cloud option
starkillerOG Mar 15, 2021
adec981
fix styling
starkillerOG Mar 15, 2021
b7385e2
Return after if
starkillerOG Mar 15, 2021
625f677
cleanup
starkillerOG Mar 15, 2021
a7bf923
add options flow tests
starkillerOG Mar 15, 2021
de117ff
fix new tests
starkillerOG Mar 15, 2021
c9a7824
fix typo in docstring
starkillerOG Mar 15, 2021
13f2faa
add missing blank line
starkillerOG Mar 16, 2021
da44e81
Merge branch 'dev' into Miio_eu_gateway
starkillerOG Apr 2, 2021
63b8660
Use async_on_unload
starkillerOG Apr 28, 2021
7c90f46
Use async_on_unload
starkillerOG Apr 28, 2021
b15ca99
Use async_setup_platforms
starkillerOG Apr 28, 2021
6575b2f
Use async_unload_platforms
starkillerOG Apr 28, 2021
91d7675
Update homeassistant/components/xiaomi_miio/__init__.py
starkillerOG Apr 28, 2021
15f0d6b
Update homeassistant/components/xiaomi_miio/const.py
starkillerOG Apr 28, 2021
bf37d48
default use_cloud False
starkillerOG Apr 28, 2021
0911afe
add options flow checks
starkillerOG Apr 28, 2021
9724ee6
fix styling
starkillerOG Apr 28, 2021
a4e90d7
fix issort
starkillerOG Apr 28, 2021
f1c70b4
add MiCloud check tests
starkillerOG Apr 28, 2021
8d097ee
fix indent
starkillerOG Apr 28, 2021
8ef0043
fix styling
starkillerOG Apr 28, 2021
b23a37a
fix tests
starkillerOG Apr 28, 2021
4033522
fix tests
starkillerOG Apr 28, 2021
f42fc22
fix black
starkillerOG Apr 28, 2021
9237d34
Merge branch 'dev' into Miio_eu_gateway
starkillerOG May 27, 2021
919e5c1
re-write config flow
starkillerOG May 27, 2021
60a5d46
add explicit return type
starkillerOG May 27, 2021
9ad89e1
update strings.json
starkillerOG Jun 4, 2021
d4d17f3
black formatting
starkillerOG Jun 4, 2021
19805ff
fix config flow
starkillerOG Jun 4, 2021
1645649
fix styling
starkillerOG Jun 4, 2021
566b1de
Fix current tests
starkillerOG Jun 5, 2021
5fd9b06
Add missing tests
starkillerOG Jun 5, 2021
fd0f19d
fix styling
starkillerOG Jun 5, 2021
5848663
add re-auth flow
starkillerOG Jun 5, 2021
cfaa1cf
fix styling
starkillerOG Jun 5, 2021
1be6804
fix reauth flow
starkillerOG Jun 5, 2021
b956b15
Add reauth flow test
starkillerOG Jun 5, 2021
bcbc912
use ConfigEntryAuthFailed
starkillerOG Jun 5, 2021
3ed50f5
also trigger reauth @ login error
starkillerOG Jun 5, 2021
2469b45
fix styling
starkillerOG Jun 5, 2021
fc7c8e5
remove unused import
starkillerOG Jun 5, 2021
ab7df97
fix spelling
starkillerOG Jun 5, 2021
b03c921
Fix spelling
starkillerOG Jun 5, 2021
8747739
fix spelling
starkillerOG Jun 5, 2021
a609f4f
remove unessesary .keys()
starkillerOG Jun 5, 2021
1db97fc
combine async_add_executor_job calls
starkillerOG Jun 5, 2021
01bbde7
Merge branch 'Miio_eu_gateway' of https://github.com/starkillerOG/hom…
starkillerOG Jun 5, 2021
8000 a6bd9e8
remove async_step_model
starkillerOG Jun 6, 2021
03ef56d
fix wrong indent
starkillerOG Jun 6, 2021
335e837
fix gatway.py
starkillerOG Jun 6, 2021
fd558bb
fix tests
starkillerOG Jun 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 54 additions & 21 deletions homeassistant/components/xiaomi_miio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ async def async_setup_entry(
)


def get_platforms(config_entry):
"""Return the platforms belonging to a config_entry."""
model = config_entry.data[CONF_MODEL]
flow_type = config_entry.data[CONF_FLOW_TYPE]

if flow_type == CONF_GATEWAY:
return GATEWAY_PLATFORMS
if flow_type == CONF_DEVICE:
if model in MODELS_SWITCH:
return SWITCH_PLATFORMS
if model in MODELS_FAN:
return FAN_PLATFORMS
if model in MODELS_LIGHT:
return LIGHT_PLATFORMS
for vacuum_model in MODELS_VACUUM:
if model.startswith(vacuum_model):
return VACUUM_PLATFORMS
for air_monitor_model in MODELS_AIR_MONITOR:
if model.startswith(air_monitor_model):
return AIR_MONITOR_PLATFORMS

return []


async def async_setup_gateway_entry(
hass: core.HomeAssistant, entry: config_entries.ConfigEntry
):
Expand All @@ -64,8 +88,10 @@ async def async_setup_gateway_entry(
if entry.unique_id.endswith("-gateway"):
hass.config_entries.async_update_entry(entry, unique_id=entry.data["mac"])

entry.async_on_unload(entry.add_update_listener(update_listener))

# Connect to gateway
gateway = ConnectXiaomiGateway(hass)
gateway = ConnectXiaomiGateway(hass, entry)
if not await gateway.async_connect_gateway(host, token):
return False
gateway_info = gateway.gateway_info
Expand Down Expand Up @@ -128,29 +154,36 @@ async def async_setup_device_entry(
hass: core.HomeAssistant, entry: config_entries.ConfigEntry
):
"""Set up the Xiaomi Miio device component from a config entry."""
model = entry.data[CONF_MODEL]

# Identify platforms to setup
platforms = []
if model in MODELS_SWITCH:
platforms = SWITCH_PLATFORMS
elif model in MODELS_FAN:
platforms = FAN_PLATFORMS
elif model in MODELS_LIGHT:
platforms = LIGHT_PLATFORMS
for vacuum_model in MODELS_VACUUM:
if model.startswith(vacuum_model):
platforms = VACUUM_PLATFORMS
for air_monitor_model in MODELS_AIR_MONITOR:
if model.startswith(air_monitor_model):
platforms = AIR_MONITOR_PLATFORMS
platforms = get_platforms(entry)

if not platforms:
return False

for platform in platforms:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, platform)
)
entry.async_on_unload(entry.add_update_listener(update_listener))

hass.config_entries.async_setup_platforms(entry, platforms)

return True


async def async_unload_entry(
hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry
):
"""Unload a config entry."""
platforms = get_platforms(config_entry)

unload_ok = await hass.config_entries.async_unload_platforms(
config_entry, platforms
)

if unload_ok:
hass.data[DOMAIN].pop(config_entry.entry_id)

return unload_ok


async def update_listener(
hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry
):
"""Handle options update."""
await hass.config_entries.async_reload(config_entry.entry_id)
Loading
0