Skip to content

Commit

Permalink
FIxed error for space in devicename + service
Browse files Browse the repository at this point in the history
  • Loading branch information
rainepretorius committed Apr 7, 2023
1 parent 62dd8b1 commit 4b894c1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
23 changes: 12 additions & 11 deletions custom_components/olarm_sensors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
except DictionaryKeyError:
data = {**config_entry.data}
options = {**config_entry.options}
if options[CONF_ALARM_CODE] is not None and data[CONF_ALARM_CODE] is not None:
if data[CONF_ALARM_CODE] is not None:
options[CONF_ALARM_CODE] = data[CONF_ALARM_CODE]

else:
Expand Down Expand Up @@ -91,6 +91,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
hass.data[DOMAIN][device["deviceId"]] = coordinator
hass.data[DOMAIN]["devices"] = devices

device_name_for_ha = device['deviceName'].lower().replace(" ", "_").replace(" ", "_").replace(" ", "_")
# Creating an instance of the Olarm API class to call the requests to arm, disarm, sleep, or stay the zones.
OLARM_API = OlarmApi(
device_id=device["deviceId"],
Expand All @@ -107,15 +108,15 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):

filedata = []
filedata.append(
f"{str(device['deviceName']).lower()}_bypass_zone:\n description: Send a request to Olarm to bypass the zone on {device['deviceName']}.\n fields:\n zone_num:\n description: 'Zone Number'\n example: '1'\n required: true\n"
f"{device_name_for_ha}_bypass_zone:\n description: Send a request to Olarm to bypass the zone on {device['deviceName']}.\n fields:\n zone_num:\n description: 'Zone Number'\n example: '1'\n required: true\n"
)
# Registering Services

# Bypass service
# Register the bypass service
hass.services.async_register(
DOMAIN,
f"{str(device['deviceName']).lower()}_bypass_zone",
f"{device_name_for_ha}_bypass_zone",
OLARM_API.bypass_zone,
vol.Schema(
{
Expand All @@ -136,57 +137,57 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):

# Area Arming
filedata.append(
f"{str(device['deviceName']).lower()}_{name}_arm:\n description: {SERVICES_TO_YAML['arm']['description']}\n".replace(
f"{device_name_for_ha}_{name}_arm:\n description: {SERVICES_TO_YAML['arm']['description']}\n".replace(
"areanumber", name
).replace(
"alarm", device["deviceName"]
)
)
hass.services.async_register(
DOMAIN,
f"{str(device['deviceName']).lower()}_{name}_arm",
f"{device_name_for_ha}_{name}_arm",
OLARM_API.arm_area,
schema=vol.Schema({vol.Optional("area", default=area + 1): int}),
)
# Area Sleeping
filedata.append(
f"{str(device['deviceName']).lower()}_{name}_sleep:\n description: {SERVICES_TO_YAML['sleep']['description']}\n".replace(
f"{device_name_for_ha}_{name}_sleep:\n description: {SERVICES_TO_YAML['sleep']['description']}\n".replace(
"areanumber", name
).replace(
"alarm", device["deviceName"]
)
)
hass.services.async_register(
DOMAIN,
f"{str(device['deviceName']).lower()}_{name}_sleep",
f"{device_name_for_ha}_{name}_sleep",
OLARM_API.sleep_area,
schema=vol.Schema({vol.Optional("area", default=area + 1): int}),
)
# Area Staying
filedata.append(
f"{str(device['deviceName']).lower()}_{name}_stay:\n description: {SERVICES_TO_YAML['stay']['description']}\n".replace(
f"{device_name_for_ha}_{name}_stay:\n description: {SERVICES_TO_YAML['stay']['description']}\n".replace(
"areanumber", name
).replace(
"alarm", device["deviceName"]
)
)
hass.services.async_register(
DOMAIN,
f"{str(device['deviceName']).lower()}_{name}_stay",
f"{device_name_for_ha}_{name}_stay",
OLARM_API.stay_area,
schema=vol.Schema({vol.Optional("area", default=area + 1): int}),
)
# Area Disarming
filedata.append(
f"{str(device['deviceName']).lower()}_{name}_disarm:\n description: {SERVICES_TO_YAML['disarm']['description']}\n".replace(
f"{device_name_for_ha}_{name}_disarm:\n description: {SERVICES_TO_YAML['disarm']['description']}\n".replace(
"areanumber", name
).replace(
"alarm", device["deviceName"]
)
)
hass.services.async_register(
DOMAIN,
f"{str(device['deviceName']).lower()}_{name}_disarm",
f"{device_name_for_ha}_{name}_disarm",
OLARM_API.disarm_area,
schema=vol.Schema({vol.Optional("area", default=area + 1): int}),
)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/olarm_sensors/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from homeassistant.components.binary_sensor import BinarySensorDeviceClass


VERSION = "2.0.1"
VERSION = "2.0.2"

DOMAIN = "olarm_sensors"
AuthenticationError = "invalid_credentials"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/olarm_sensors/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"config_flow": true,
"entrypoint": "olarm_sensors",
"iot_class": "cloud_polling",
"version": "2.0.1"
"version": "2.0.2"
}
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"description": "Integration for Olarm devices",
"domains": ["binary_sensor", "alarm_control_panel", "button"],
"documentation": "https://github.com/rainepretorius/olarm-ha-integration/blob/main/README.md",
"version": "2.0.1",
"version": "2.0.2",
"iot_class": ["Cloud Polling"]
}

0 comments on commit 4b894c1

Please sign in to comment.