Add Somfy hub as device (#35209)

This commit is contained in:
tetienne 2020-05-17 23:14:11 +02:00 committed by GitHub
parent 8eb7777561
commit 3815d7d74f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 5 deletions

View File

@ -3,12 +3,17 @@ import asyncio
from datetime import timedelta from datetime import timedelta
import logging import logging
from pymfy.api.devices.category import Category
from requests import HTTPError from requests import HTTPError
import voluptuous as vol import voluptuous as vol
from homeassistant.components.somfy import config_flow from homeassistant.components.somfy import config_flow
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv from homeassistant.helpers import (
config_entry_oauth2_flow,
config_validation as cv,
device_registry as dr,
)
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
from homeassistant.util import Throttle from homeassistant.util import Throttle
@ -86,6 +91,20 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
await update_all_devices(hass) await update_all_devices(hass)
device_registry = await dr.async_get_registry(hass)
devices = hass.data[DOMAIN][DEVICES]
hubs = [device for device in devices if Category.HUB.value in device.categories]
for hub in hubs:
device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, hub.id)},
manufacturer="Somfy",
name=hub.name,
model=hub.type,
)
for component in SOMFY_COMPONENTS: for component in SOMFY_COMPONENTS:
hass.async_create_task( hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component) hass.config_entries.async_forward_entry_setup(entry, component)
@ -134,7 +153,7 @@ class SomfyEntity(Entity):
"identifiers": {(DOMAIN, self.unique_id)}, "identifiers": {(DOMAIN, self.unique_id)},
"name": self.name, "name": self.name,
"model": self.device.type, "model": self.device.type,
"via_hub": (DOMAIN, self.device.site_id), "via_hub": (DOMAIN, self.device.parent_id),
# For the moment, Somfy only returns their own device. # For the moment, Somfy only returns their own device.
"manufacturer": "Somfy", "manufacturer": "Somfy",
} }

View File

@ -5,5 +5,5 @@
"documentation": "https://www.home-assistant.io/integrations/somfy", "documentation": "https://www.home-assistant.io/integrations/somfy",
"dependencies": ["http"], "dependencies": ["http"],
"codeowners": ["@tetienne"], "codeowners": ["@tetienne"],
"requirements": ["pymfy==0.7.1"] "requirements": ["pymfy==0.9.0"]
} }

View File

@ -1447,7 +1447,7 @@ pymediaroom==0.6.4
pymelcloud==2.5.2 pymelcloud==2.5.2
# homeassistant.components.somfy # homeassistant.components.somfy
pymfy==0.7.1 pymfy==0.9.0
# homeassistant.components.xiaomi_tv # homeassistant.components.xiaomi_tv
pymitv==1.4.3 pymitv==1.4.3

View File

@ -621,7 +621,7 @@ pymailgunner==1.4
pymelcloud==2.5.2 pymelcloud==2.5.2
# homeassistant.components.somfy # homeassistant.components.somfy
pymfy==0.7.1 pymfy==0.9.0
# homeassistant.components.mochad # homeassistant.components.mochad
pymochad==0.2.0 pymochad==0.2.0