Move xs1 base entity to separate module (#126199)

This commit is contained in:
epenet 2024-09-18 11:00:06 +02:00 committed by GitHub
parent 8827b5510f
commit dd77c6b59f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 29 additions and 23 deletions

View file

@ -1,6 +1,5 @@
"""Support for the EZcontrol XS1 gateway."""
import asyncio
import logging
import voluptuous as vol
@ -17,7 +16,6 @@ from homeassistant.const import (
from homeassistant.core import HomeAssistant
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
@ -44,11 +42,6 @@ CONFIG_SCHEMA = vol.Schema(
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR, Platform.SWITCH]
# Lock used to limit the amount of concurrent update requests
# as the XS1 Gateway can only handle a very
# small amount of concurrent requests
UPDATE_LOCK = asyncio.Lock()
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up XS1 integration."""
@ -88,16 +81,3 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
discovery.load_platform(hass, platform, DOMAIN, {}, config)
return True
class XS1DeviceEntity(Entity):
"""Representation of a base XS1 device."""
def __init__(self, device):
"""Initialize the XS1 device."""
self.device = device
async def async_update(self):
"""Retrieve latest device state."""
async with UPDATE_LOCK:
await self.hass.async_add_executor_job(self.device.update)

View file

@ -16,7 +16,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import ACTUATORS, DOMAIN as COMPONENT_DOMAIN, SENSORS, XS1DeviceEntity
from . import ACTUATORS, DOMAIN as COMPONENT_DOMAIN, SENSORS
from .entity import XS1DeviceEntity
MIN_TEMP = 8
MAX_TEMP = 25

View file

@ -0,0 +1,23 @@
"""Support for the EZcontrol XS1 gateway."""
import asyncio
from homeassistant.helpers.entity import Entity
# Lock used to limit the amount of concurrent update requests
# as the XS1 Gateway can only handle a very
# small amount of concurrent requests
UPDATE_LOCK = asyncio.Lock()
class XS1DeviceEntity(Entity):
"""Representation of a base XS1 device."""
def __init__(self, device):
"""Initialize the XS1 device."""
self.device = device
async def async_update(self):
"""Retrieve latest device state."""
async with UPDATE_LOCK:
await self.hass.async_add_executor_job(self.device.update)

View file

@ -9,7 +9,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import ACTUATORS, DOMAIN as COMPONENT_DOMAIN, SENSORS, XS1DeviceEntity
from . import ACTUATORS, DOMAIN as COMPONENT_DOMAIN, SENSORS
from .entity import XS1DeviceEntity
def setup_platform(

View file

@ -11,7 +11,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import ACTUATORS, DOMAIN as COMPONENT_DOMAIN, XS1DeviceEntity
from . import ACTUATORS, DOMAIN as COMPONENT_DOMAIN
from .entity import XS1DeviceEntity
def setup_platform(