diff --git a/hatasmota/discovery.py b/hatasmota/discovery.py index ccc36f0..5bbc3a8 100644 --- a/hatasmota/discovery.py +++ b/hatasmota/discovery.py @@ -356,29 +356,19 @@ def has_entities_with_platform(discovery_msg, platform): return any(x is not None for (x, _) in entities) -def get_entity(config, mqtt_client, create_task): +def get_entity(config, mqtt_client): """Create entity for the given platform.""" platform = config.platform if platform == "binary_sensor": - return TasmotaSwitch( - config=config, mqtt_client=mqtt_client, create_task=create_task - ) + return TasmotaSwitch(config=config, mqtt_client=mqtt_client) if platform == "light": - return TasmotaLight( - config=config, mqtt_client=mqtt_client, create_task=create_task - ) + return TasmotaLight(config=config, mqtt_client=mqtt_client) if platform == "sensor": - return TasmotaSensor( - config=config, mqtt_client=mqtt_client, create_task=create_task - ) + return TasmotaSensor(config=config, mqtt_client=mqtt_client) if platform == "status_sensor": - return TasmotaStatusSensor( - config=config, mqtt_client=mqtt_client, create_task=create_task - ) + return TasmotaStatusSensor(config=config, mqtt_client=mqtt_client) if platform == "switch": - return TasmotaRelay( - config=config, mqtt_client=mqtt_client, create_task=create_task - ) + return TasmotaRelay(config=config, mqtt_client=mqtt_client) return None diff --git a/hatasmota/entity.py b/hatasmota/entity.py index 216ca14..1df870f 100644 --- a/hatasmota/entity.py +++ b/hatasmota/entity.py @@ -36,10 +36,9 @@ class TasmotaAvailabilityConfig(TasmotaEntityConfig): class TasmotaEntity: """Base class for Tasmota entities.""" - def __init__(self, config, create_task, mqtt_client): + def __init__(self, config, mqtt_client): """Initialize.""" self._cfg = config - self._create_task = create_task self._mqtt_client = mqtt_client self._on_state_callback = None super().__init__() diff --git a/hatasmota/status_sensor.py b/hatasmota/status_sensor.py index d39f2dc..03dfe7a 100644 --- a/hatasmota/status_sensor.py +++ b/hatasmota/status_sensor.py @@ -1,4 +1,5 @@ """Tasmota status sensor.""" +import asyncio import json import logging from datetime import datetime, timedelta @@ -186,7 +187,7 @@ async def _poll_status(self): def poll_status(self): """Poll for status.""" - self._create_task(self._poll_status()) + asyncio.create_task(self._poll_status()) async def subscribe_topics(self): """Subscribe to topics.""" @@ -205,7 +206,7 @@ def state_message_received(msg): state = get_value_by_path(payload, STATUS_PATHS[self._cfg.sensor]) if state is not None: if self._cfg.sensor in SINGLE_SHOT: - self._create_task(self._unsubscribe_state_topics()) + asyncio.create_task(self._unsubscribe_state_topics()) if self._cfg.sensor == SENSOR_STATUS_LAST_RESTART_TIME: state = datetime.utcnow() - timedelta(seconds=int(state)) self._on_state_callback(state)