diff --git a/changelog b/changelog index 2bbe38b4..f6a75639 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,7 @@ aarlo +0.8.1a11 + Remove deprecated constants. + Fixed setup code. 0.8.1a10 Add import notice Add siren support. diff --git a/custom_components/aarlo/__init__.py b/custom_components/aarlo/__init__.py index 9cd4b9ca..a0f0af2c 100644 --- a/custom_components/aarlo/__init__.py +++ b/custom_components/aarlo/__init__.py @@ -53,7 +53,7 @@ from .cfg import BlendedCfg, PyaarloCfg -__version__ = "0.8.1a10" +__version__ = "0.8.1a11" _LOGGER = logging.getLogger(__name__) @@ -186,7 +186,7 @@ ] -def setup(hass: HomeAssistant, config: ConfigType) -> bool: +async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up an momentary component. """ @@ -237,7 +237,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: _LOGGER.debug(f'async setup for aarlo') # Get the blended config. - cfg = BlendedCfg(entry.data, entry.options) + cfg = BlendedCfg(hass, entry.data, entry.options) domain_config = cfg.domain_config injection_service = domain_config.get(CONF_INJECTION_SERVICE, False) @@ -365,7 +365,7 @@ async def update_listener(hass: HomeAssistant, entry: ConfigEntry): return _LOGGER.debug("reconfiguring...") - cfg = BlendedCfg(entry.data, entry.options) + cfg = BlendedCfg(hass, entry.data, entry.options) hass.data[COMPONENT_CONFIG] = { COMPONENT_DOMAIN: cfg.domain_config, str(Platform.ALARM_CONTROL_PANEL): cfg.alarm_config, diff --git a/custom_components/aarlo/alarm_control_panel.py b/custom_components/aarlo/alarm_control_panel.py index c228fc51..1d0c3f2f 100644 --- a/custom_components/aarlo/alarm_control_panel.py +++ b/custom_components/aarlo/alarm_control_panel.py @@ -17,10 +17,9 @@ from homeassistant.components import websocket_api from homeassistant.components.alarm_control_panel import ( DOMAIN as ALARM_DOMAIN, - FORMAT_NUMBER, - FORMAT_TEXT, AlarmControlPanelEntity, AlarmControlPanelEntityFeature, + CodeFormat ) from homeassistant.const import ( ATTR_ATTRIBUTION, @@ -168,8 +167,8 @@ def _code_format(code): if code is None or code == "": return None if isinstance(code, str) and re.search("^\\d+$", code): - return FORMAT_NUMBER - return FORMAT_TEXT + return CodeFormat.NUMBER + return CodeFormat.TEXT def _code_validate(code, code_to_check, state): diff --git a/custom_components/aarlo/cfg.py b/custom_components/aarlo/cfg.py index 2fa20785..bf640099 100644 --- a/custom_components/aarlo/cfg.py +++ b/custom_components/aarlo/cfg.py @@ -16,12 +16,10 @@ import copy import logging -from datetime import timedelta import voluptuous as vol from homeassistant.const import ( - ATTR_ENTITY_ID, CONF_CODE, CONF_HOST, CONF_MONITORED_CONDITIONS, @@ -31,12 +29,8 @@ CONF_TRIGGER_TIME, CONF_USERNAME, Platform, - STATE_ALARM_ARMED_AWAY, - STATE_ALARM_ARMED_HOME, - STATE_ALARM_ARMED_NIGHT, STATE_ALARM_DISARMED, - STATE_ALARM_TRIGGERED, - TEMP_CELSIUS, + UnitOfTemperature ) from homeassistant.helpers import config_validation as cv from homeassistant.util.yaml import load_yaml, save_yaml @@ -220,7 +214,7 @@ "captured_today": ["Captured Today", None, "file-video", CAPTURED_TODAY_KEY], "battery_level": ["Battery Level", "%", "battery-50", BATTERY_KEY], "signal_strength": ["Signal Strength", None, "signal", SIGNAL_STR_KEY], - "temperature": ["Temperature", TEMP_CELSIUS, "thermometer", TEMPERATURE_KEY], + "temperature": ["Temperature", UnitOfTemperature.CELSIUS, "thermometer", TEMPERATURE_KEY], "humidity": ["Humidity", "%", "water-percent", HUMIDITY_KEY], "air_quality": ["Air Quality", "ppm", "biohazard", AIR_QUALITY_KEY], } @@ -247,8 +241,6 @@ vol.Optional(CONF_DOORBELL_SILENCE, default=SILENT_MODE_DEFAULT): cv.boolean, }) -AARLO_CONFIG_FILE = "/config/aarlo.yaml" - DEFAULT_OPTIONS = { "alarm_control_panel_disarmed_mode_name": "disarmed", "alarm_control_panel_home_mode_name": "home", @@ -287,6 +279,10 @@ } +def _default_config_file(hass) -> str: + return hass.config.path("aarlo.yaml") + + def _fix_config(config): """Find and return the aarlo entry from any platform config. """ @@ -325,7 +321,8 @@ class BlendedCfg(object): them with flow data and options. """ - def __init__(self, data, options): + def __init__(self, hass, data, options): + self._hass = hass self._main_config = {} self._alarm_config = {} self._binary_sensor_config = {} @@ -341,7 +338,7 @@ def _load(self): # Read in current config config = {} try: - config = load_yaml(AARLO_CONFIG_FILE) + config = load_yaml(_default_config_file(self._hass)) except Exception as e: _LOGGER.debug(f"failed to read aarlo config {str(e)}") @@ -350,7 +347,7 @@ def _load(self): self._main_config = AARLO_SCHEMA({}) self._main_config.update(config.get(COMPONENT_DOMAIN, {})) - _LOGGER.debug(f"l-config-file={AARLO_CONFIG_FILE}") + _LOGGER.debug(f"l-config-file={_default_config_file(self._hass)}") _LOGGER.debug(f"l-main-config={self._main_config}") def _merge(self, data, options): @@ -397,7 +394,7 @@ class UpgradeCfg(object): """ @staticmethod - def create_file_config(config): + def create_file_config(hass, config): """ Take the current aarlo config and make the new yaml file. Aarlo seems to need a lot of fine tuning so rather than get rid of @@ -405,6 +402,8 @@ def create_file_config(config): where the user can configure things. """ + _LOGGER.debug(f"new-config-file={_default_config_file(hass)}") + # A default config. default_aarlo_config = AARLO_FULL_SCHEMA({ CONF_USERNAME: "", @@ -425,7 +424,7 @@ def create_file_config(config): # Save it out. try: - save_yaml(AARLO_CONFIG_FILE, { + save_yaml(_default_config_file(hass), { "version": 1, COMPONENT_DOMAIN: file_config, }) diff --git a/custom_components/aarlo/config_flow.py b/custom_components/aarlo/config_flow.py index a75565c2..bd4fc5c1 100644 --- a/custom_components/aarlo/config_flow.py +++ b/custom_components/aarlo/config_flow.py @@ -154,7 +154,7 @@ async def async_step_import(self, import_data): """Import momentary config from configuration.yaml.""" _LOGGER.info("importing aarlo YAML") - UpgradeCfg.create_file_config(import_data) + UpgradeCfg.create_file_config(self.hass, import_data) data = UpgradeCfg.create_flow_data(import_data) options = UpgradeCfg.create_flow_options(import_data) diff --git a/custom_components/aarlo/manifest.json b/custom_components/aarlo/manifest.json index a1f79fe2..ab9bee25 100644 --- a/custom_components/aarlo/manifest.json +++ b/custom_components/aarlo/manifest.json @@ -15,5 +15,5 @@ "unidecode", "pyaarlo>=0.8.0.2" ], - "version": "0.8.1a10" + "version": "0.8.1a11" } diff --git a/custom_components/aarlo/sensor.py b/custom_components/aarlo/sensor.py index 7016b614..3eb9ff2f 100644 --- a/custom_components/aarlo/sensor.py +++ b/custom_components/aarlo/sensor.py @@ -14,7 +14,7 @@ from homeassistant.const import ( ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS, - TEMP_CELSIUS, + UnitOfTemperature, ) from homeassistant.core import callback from homeassistant.helpers.config_validation import PLATFORM_SCHEMA @@ -74,7 +74,9 @@ "captured_today": ["Captured Today", None, None, "file-video", CAPTURED_TODAY_KEY], "battery_level": ["Battery Level", SensorDeviceClass.BATTERY, "%", "battery-50", BATTERY_KEY], "signal_strength": ["Signal Strength", None, None, "signal", SIGNAL_STR_KEY], - "temperature": ["Temperature", SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, "thermometer", TEMPERATURE_KEY], + "temperature": ["Temperature", SensorDeviceClass.TEMPERATURE, + UnitOfTemperature.CELSIUS, + "thermometer", TEMPERATURE_KEY], "humidity": ["Humidity", SensorDeviceClass.HUMIDITY, "%", "water-percent", HUMIDITY_KEY], "air_quality": ["Air Quality", SensorDeviceClass.AQI, "ppm", "biohazard", AIR_QUALITY_KEY], }