Pass the hass object to all MQTT component constructors (#52124)
This commit is contained in:
parent
77de233679
commit
80ae346318
6 changed files with 24 additions and 24 deletions
|
@ -32,33 +32,33 @@ async def async_setup_platform(
|
|||
):
|
||||
"""Set up MQTT camera through configuration.yaml."""
|
||||
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
|
||||
await _async_setup_entity(async_add_entities, config)
|
||||
await _async_setup_entity(hass, async_add_entities, config)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up MQTT camera dynamically through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, async_add_entities, config_entry=config_entry
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
await async_setup_entry_helper(hass, camera.DOMAIN, setup, PLATFORM_SCHEMA)
|
||||
|
||||
|
||||
async def _async_setup_entity(
|
||||
async_add_entities, config, config_entry=None, discovery_data=None
|
||||
hass, async_add_entities, config, config_entry=None, discovery_data=None
|
||||
):
|
||||
"""Set up the MQTT Camera."""
|
||||
async_add_entities([MqttCamera(config, config_entry, discovery_data)])
|
||||
async_add_entities([MqttCamera(hass, config, config_entry, discovery_data)])
|
||||
|
||||
|
||||
class MqttCamera(MqttEntity, Camera):
|
||||
"""representation of a MQTT camera."""
|
||||
|
||||
def __init__(self, config, config_entry, discovery_data):
|
||||
def __init__(self, hass, config, config_entry, discovery_data):
|
||||
"""Initialize the MQTT Camera."""
|
||||
self._last_image = None
|
||||
|
||||
Camera.__init__(self)
|
||||
MqttEntity.__init__(self, None, config, config_entry, discovery_data)
|
||||
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
|
||||
|
||||
@staticmethod
|
||||
def config_schema():
|
||||
|
|
|
@ -151,13 +151,13 @@ async def async_setup_entity_json(
|
|||
hass, config: ConfigType, async_add_entities, config_entry, discovery_data
|
||||
):
|
||||
"""Set up a MQTT JSON Light."""
|
||||
async_add_entities([MqttLightJson(config, config_entry, discovery_data)])
|
||||
async_add_entities([MqttLightJson(hass, config, config_entry, discovery_data)])
|
||||
|
||||
|
||||
class MqttLightJson(MqttEntity, LightEntity, RestoreEntity):
|
||||
"""Representation of a MQTT JSON light."""
|
||||
|
||||
def __init__(self, config, config_entry, discovery_data):
|
||||
def __init__(self, hass, config, config_entry, discovery_data):
|
||||
"""Initialize MQTT JSON light."""
|
||||
self._state = False
|
||||
self._supported_features = 0
|
||||
|
@ -176,7 +176,7 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity):
|
|||
self._white_value = None
|
||||
self._xy = None
|
||||
|
||||
MqttEntity.__init__(self, None, config, config_entry, discovery_data)
|
||||
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
|
||||
|
||||
@staticmethod
|
||||
def config_schema():
|
||||
|
|
|
@ -87,13 +87,13 @@ async def async_setup_entity_template(
|
|||
hass, config, async_add_entities, config_entry, discovery_data
|
||||
):
|
||||
"""Set up a MQTT Template light."""
|
||||
async_add_entities([MqttLightTemplate(config, config_entry, discovery_data)])
|
||||
async_add_entities([MqttLightTemplate(hass, config, config_entry, discovery_data)])
|
||||
|
||||
|
||||
class MqttLightTemplate(MqttEntity, LightEntity, RestoreEntity):
|
||||
"""Representation of a MQTT Template light."""
|
||||
|
||||
def __init__(self, config, config_entry, discovery_data):
|
||||
def __init__(self, hass, config, config_entry, discovery_data):
|
||||
"""Initialize a MQTT Template light."""
|
||||
self._state = False
|
||||
|
||||
|
@ -108,7 +108,7 @@ class MqttLightTemplate(MqttEntity, LightEntity, RestoreEntity):
|
|||
self._hs = None
|
||||
self._effect = None
|
||||
|
||||
MqttEntity.__init__(self, None, config, config_entry, discovery_data)
|
||||
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
|
||||
|
||||
@staticmethod
|
||||
def config_schema():
|
||||
|
|
|
@ -27,22 +27,22 @@ PLATFORM_SCHEMA = vol.All(
|
|||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up MQTT vacuum through configuration.yaml."""
|
||||
await async_setup_reload_service(hass, MQTT_DOMAIN, PLATFORMS)
|
||||
await _async_setup_entity(async_add_entities, config)
|
||||
await _async_setup_entity(hass, async_add_entities, config)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up MQTT vacuum dynamically through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, async_add_entities, config_entry=config_entry
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
)
|
||||
await async_setup_entry_helper(hass, DOMAIN, setup, PLATFORM_SCHEMA)
|
||||
|
||||
|
||||
async def _async_setup_entity(
|
||||
async_add_entities, config, config_entry=None, discovery_data=None
|
||||
hass, async_add_entities, config, config_entry=None, discovery_data=None
|
||||
):
|
||||
"""Set up the MQTT vacuum."""
|
||||
setup_entity = {LEGACY: async_setup_entity_legacy, STATE: async_setup_entity_state}
|
||||
await setup_entity[config[CONF_SCHEMA]](
|
||||
config, async_add_entities, config_entry, discovery_data
|
||||
hass, config, async_add_entities, config_entry, discovery_data
|
||||
)
|
||||
|
|
|
@ -151,16 +151,16 @@ PLATFORM_SCHEMA_LEGACY = (
|
|||
|
||||
|
||||
async def async_setup_entity_legacy(
|
||||
config, async_add_entities, config_entry, discovery_data
|
||||
hass, config, async_add_entities, config_entry, discovery_data
|
||||
):
|
||||
"""Set up a MQTT Vacuum Legacy."""
|
||||
async_add_entities([MqttVacuum(config, config_entry, discovery_data)])
|
||||
async_add_entities([MqttVacuum(hass, config, config_entry, discovery_data)])
|
||||
|
||||
|
||||
class MqttVacuum(MqttEntity, VacuumEntity):
|
||||
"""Representation of a MQTT-controlled legacy vacuum."""
|
||||
|
||||
def __init__(self, config, config_entry, discovery_data):
|
||||
def __init__(self, hass, config, config_entry, discovery_data):
|
||||
"""Initialize the vacuum."""
|
||||
self._cleaning = False
|
||||
self._charging = False
|
||||
|
@ -171,7 +171,7 @@ class MqttVacuum(MqttEntity, VacuumEntity):
|
|||
self._fan_speed = "unknown"
|
||||
self._fan_speed_list = []
|
||||
|
||||
MqttEntity.__init__(self, None, config, config_entry, discovery_data)
|
||||
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
|
||||
|
||||
@staticmethod
|
||||
def config_schema():
|
||||
|
|
|
@ -135,22 +135,22 @@ PLATFORM_SCHEMA_STATE = (
|
|||
|
||||
|
||||
async def async_setup_entity_state(
|
||||
config, async_add_entities, config_entry, discovery_data
|
||||
hass, config, async_add_entities, config_entry, discovery_data
|
||||
):
|
||||
"""Set up a State MQTT Vacuum."""
|
||||
async_add_entities([MqttStateVacuum(config, config_entry, discovery_data)])
|
||||
async_add_entities([MqttStateVacuum(hass, config, config_entry, discovery_data)])
|
||||
|
||||
|
||||
class MqttStateVacuum(MqttEntity, StateVacuumEntity):
|
||||
"""Representation of a MQTT-controlled state vacuum."""
|
||||
|
||||
def __init__(self, config, config_entry, discovery_data):
|
||||
def __init__(self, hass, config, config_entry, discovery_data):
|
||||
"""Initialize the vacuum."""
|
||||
self._state = None
|
||||
self._state_attrs = {}
|
||||
self._fan_speed_list = []
|
||||
|
||||
MqttEntity.__init__(self, None, config, config_entry, discovery_data)
|
||||
MqttEntity.__init__(self, hass, config, config_entry, discovery_data)
|
||||
|
||||
@staticmethod
|
||||
def config_schema():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue