From 430f6a18400e032ed741e100e3fbbc102e02d814 Mon Sep 17 00:00:00 2001 From: Samuel Spagl <46893256+samuelspagl@users.noreply.github.com> Date: Mon, 1 Apr 2024 10:49:48 +0200 Subject: [PATCH] Add additional validation for CONF_ENTRY_MAX_VOLUME value in the setup process to be greater than zero (#24) Fixes #19 --- CHANGELOG.md | 8 ++++++++ custom_components/samsung_soundbar/config_flow.py | 3 ++- custom_components/samsung_soundbar/manifest.json | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c8724f..2ee9f29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [0.3.2] Fix division by zero + +### Added + +- The config flow now also checks whether the `int` provided for `CONF_ENTRY_MAX_VOLUME` is + greater than `1` and lower than `100`. This will make sure that a division by zero cannot happen. +- Add default value `100` to `CONF_ENTRY_MAX_VOLUME` + ## [0.3.1] Documentation enhancements ### Changed diff --git a/custom_components/samsung_soundbar/config_flow.py b/custom_components/samsung_soundbar/config_flow.py index a7ec8a8..fa9cff1 100644 --- a/custom_components/samsung_soundbar/config_flow.py +++ b/custom_components/samsung_soundbar/config_flow.py @@ -5,6 +5,7 @@ from homeassistant import config_entries from homeassistant.helpers.aiohttp_client import async_get_clientsession from pysmartthings import APIResponseError +from voluptuous import All, Range from .const import (CONF_ENTRY_API_KEY, CONF_ENTRY_DEVICE_ID, CONF_ENTRY_DEVICE_NAME, CONF_ENTRY_MAX_VOLUME, DOMAIN) @@ -45,7 +46,7 @@ async def async_step_user(self, user_input=None): vol.Required(CONF_ENTRY_API_KEY): str, vol.Required(CONF_ENTRY_DEVICE_ID): str, vol.Required(CONF_ENTRY_DEVICE_NAME): str, - vol.Required(CONF_ENTRY_MAX_VOLUME): int, + vol.Required(CONF_ENTRY_MAX_VOLUME, default=100): All(int, Range(min=1, max=100)) } ), ) diff --git a/custom_components/samsung_soundbar/manifest.json b/custom_components/samsung_soundbar/manifest.json index b3363ff..70a039f 100644 --- a/custom_components/samsung_soundbar/manifest.json +++ b/custom_components/samsung_soundbar/manifest.json @@ -8,5 +8,5 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/samuelspagl/ha_samsung_soundbar/issues", "requirements": ["pysmartthings"], - "version": "0.3.1" + "version": "0.3.2" }