Skip to content

Commit

Permalink
Alpha 11 (#880)
Browse files Browse the repository at this point in the history
* Remove deprecated constants.

* Fixed setup code.

* Fixed setup code.

* Code tidy.
  • Loading branch information
twrecked authored Feb 4, 2024
1 parent 7817e6f commit 8c022c1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 27 deletions.
3 changes: 3 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
aarlo
0.8.1a11
Remove deprecated constants.
Fixed setup code.
0.8.1a10
Add import notice
Add siren support.
Expand Down
8 changes: 4 additions & 4 deletions custom_components/aarlo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from .cfg import BlendedCfg, PyaarloCfg


__version__ = "0.8.1a10"
__version__ = "0.8.1a11"

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -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.
"""

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions custom_components/aarlo/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
29 changes: 14 additions & 15 deletions custom_components/aarlo/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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],
}
Expand All @@ -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",
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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)}")

Expand All @@ -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):
Expand Down Expand Up @@ -397,14 +394,16 @@ 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
the options or clutter up the config flow system I'm adding a text file
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: "",
Expand All @@ -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,
})
Expand Down
2 changes: 1 addition & 1 deletion custom_components/aarlo/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/aarlo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"unidecode",
"pyaarlo>=0.8.0.2"
],
"version": "0.8.1a10"
"version": "0.8.1a11"
}
6 changes: 4 additions & 2 deletions custom_components/aarlo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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],
}
Expand Down

0 comments on commit 8c022c1

Please sign in to comment.