diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..df064370 Binary files /dev/null and b/.DS_Store differ diff --git a/custom_components/.DS_Store b/custom_components/.DS_Store new file mode 100644 index 00000000..9a2fff4e Binary files /dev/null and b/custom_components/.DS_Store differ diff --git a/custom_components/nhc2/__init__.py b/custom_components/nhc2/__init__.py index 7a046ad5..5c758b24 100644 --- a/custom_components/nhc2/__init__.py +++ b/custom_components/nhc2/__init__.py @@ -12,7 +12,7 @@ from .const import DOMAIN, KEY_GATEWAY, CONF_SWITCHES_AS_LIGHTS from .helpers import extract_versions -REQUIREMENTS = ['nhc2-coco==1.0.1'] +REQUIREMENTS = ['nhc2-coco==1.1.3'] _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/nhc2/config_flow.py b/custom_components/nhc2/config_flow.py index 1256d903..770fc1c8 100644 --- a/custom_components/nhc2/config_flow.py +++ b/custom_components/nhc2/config_flow.py @@ -8,7 +8,7 @@ from nhc2_coco.coco_discover_profiles import CoCoDiscoverProfiles from nhc2_coco.coco_login_validation import CoCoLoginValidation -from .const import DOMAIN, CONF_SWITCHES_AS_LIGHTS +from .const import DOMAIN, CONF_SWITCHES_AS_LIGHTS, KEY_MANUAL _LOGGER = logging.getLogger(__name__) @@ -62,7 +62,7 @@ async def async_step_user(self, user_input=None): return await self._show_user_config_form() return self.async_create_entry( - title=user_name + ' (' + self._selected_coco[1].replace(':', '') + ')', + title=user_name + ' (' + host + ')', data={ CONF_HOST: host, CONF_ADDRESS: self._selected_coco[1], @@ -84,25 +84,37 @@ async def async_step_user(self, user_input=None): 'Type': 'hobby' }) - found_coco_count = len(self._all_cocos) if self._all_cocos else 0 - # If there is only one controller, we continue to the next step - if found_coco_count == 1: - self._selected_coco = self._all_cocos[0] - return await self._show_user_config_form() - - if found_coco_count > 1: - return await self._show_host_config_form() - - return self.async_abort(reason="no_controller_found") + return await self._show_host_config_form() async def async_step_host(self, user_input=None): self._errors = {} - _LOGGER.debug(self.hass.config_entries.async_entries(DOMAIN)) - - self._selected_coco = \ - list(filter(lambda x: x[0] == user_input[CONF_HOST] or x[3] == user_input[CONF_HOST], self._all_cocos))[0] + if user_input[CONF_HOST] == KEY_MANUAL: + return await self._show_manual_host_config_form() + else: + self._selected_coco = \ + list(filter(lambda x: x[0] == user_input[CONF_HOST] or x[3] == user_input[CONF_HOST], self._all_cocos))[0] return await self._show_user_config_form() + async def async_step_manual_host(self, user_input=None): + self._errors = {} + + disc = CoCoDiscoverProfiles(user_input[CONF_HOST]) + self._all_cocos = await disc.get_all_profiles() + if self._all_cocos is not None and len(self._all_cocos) == 1: + self._selected_coco = self._all_cocos[0] + _LOGGER.debug(str(self._all_cocos)) + for coco in self._all_cocos: + if coco[2] is not None: + coco[2].insert(0, { + 'Uuid': 'hobby', + 'Name': 'hobby', + 'Type': 'hobby' + }) + + return await self._show_user_config_form() + else: + return self.async_abort(reason="no_controller_found") + async def _show_host_config_form(self): """Show the configuration form to edit NHC2 data.""" host_listing = {} @@ -112,6 +124,9 @@ async def _show_host_config_form(self): host_listing[dkey] = [x[3] + ' (' + x[0] + ')'] if i == 0: first = dkey + host_listing[KEY_MANUAL] = 'Manual Input' + if first is None: + first = KEY_MANUAL return self.async_show_form( step_id='host', errors=self._errors, @@ -134,8 +149,7 @@ async def _show_user_config_form(self): step_id='user', errors=self._errors, description_placeholders={ - "host": self._selected_coco[3] if self._selected_coco[3] is not None else self._selected_coco[0], - "address": self._selected_coco[1] + "host": self._selected_coco[3] if self._selected_coco[3] is not None else self._selected_coco[0] }, data_schema=vol.Schema({ vol.Required(CONF_USERNAME, default=first): vol.In(profile_listing), @@ -143,3 +157,13 @@ async def _show_user_config_form(self): vol.Optional(CONF_SWITCHES_AS_LIGHTS, default=False): bool }), ) + + async def _show_manual_host_config_form(self): + """Show the configuration form to edit NHC2 data.""" + return self.async_show_form( + step_id='manual_host', + errors=self._errors, + data_schema=vol.Schema({ + vol.Required(CONF_HOST, default=None): str + }), + ) diff --git a/custom_components/nhc2/const.py b/custom_components/nhc2/const.py index ababe9ed..da1667e2 100644 --- a/custom_components/nhc2/const.py +++ b/custom_components/nhc2/const.py @@ -9,3 +9,4 @@ COVER = 'Cover' CONF_SWITCHES_AS_LIGHTS = 'switches_as_lights' DEFAULT_PORT = 8883 +KEY_MANUAL = 'MANUAL_IP_HOST' diff --git a/custom_components/nhc2/light.py b/custom_components/nhc2/light.py index 2718cde9..3475d921 100644 --- a/custom_components/nhc2/light.py +++ b/custom_components/nhc2/light.py @@ -34,7 +34,7 @@ def __init__(self, nhc2light: CoCoLight, optimistic=True): self._optimistic = optimistic self._is_on = nhc2light.is_on if self._nhc2light.support_brightness: - self._brightness = int((self._nhc2light.brightness + 1) * 2.54) + self._brightness = round(self._nhc2light.brightness * 2.55) else: self._brightness = None nhc2light.on_change = self._on_change @@ -42,7 +42,7 @@ def __init__(self, nhc2light: CoCoLight, optimistic=True): def _on_change(self): self._is_on = self._nhc2light.is_on if self._nhc2light.support_brightness: - self._brightness = int((self._nhc2light.brightness + 1) * 2.54) + self._brightness = round(self._nhc2light.brightness * 2.55) self.schedule_update_ha_state() def turn_off(self, **kwargs) -> None: @@ -59,12 +59,10 @@ async def async_turn_on(self, **kwargs): brightness = kwargs.get(ATTR_BRIGHTNESS) if self._nhc2light.support_brightness and brightness is not None: - self._nhc2light.brightness(int((brightness / 2.54) - 1)) + self._nhc2light.set_brightness(round((brightness) / 2.55)) if self._optimistic: self._is_on = True - if self._nhc2light.support_brightness and brightness is not None: - self._brightness = int((int((brightness / 2.54) - 1) + 1) * 2.54) self.schedule_update_ha_state() async def async_turn_off(self, **kwargs): diff --git a/custom_components/nhc2/manifest.json b/custom_components/nhc2/manifest.json index cdb43191..1176d8f1 100644 --- a/custom_components/nhc2/manifest.json +++ b/custom_components/nhc2/manifest.json @@ -1,7 +1,7 @@ { "domain": "nhc2", "name": "Niko Home Control II", - "requirements": ["nhc2-coco==1.0.1"], + "requirements": ["nhc2-coco==1.1.3"], "config_flow": true, "issue_tracker": "https://github.com/filipvh/hass-nhc2/issues", "documentation": "https://github.com/filipvh/hass-nhc2/blob/master/README.md", diff --git a/custom_components/nhc2/strings.json b/custom_components/nhc2/strings.json index 0edc38ed..425ac329 100644 --- a/custom_components/nhc2/strings.json +++ b/custom_components/nhc2/strings.json @@ -2,7 +2,7 @@ "config": { "step": { "user": { - "description": "Configuring controller {host} ({address}).\n One option is to activate the 'Niko Hobby API' on the Connected Services page at: https://mynikohomecontrol.niko.eu/nlbe/ConnectedServices/Overview or you can use a touchscreen profile. Touchscreen profiles can be create in the 'Niko Home Control programming software' under Dashboard > Touchscreens.", + "description": "Configuring controller {host}.\n One option is to activate the 'Niko Hobby API' on the Connected Services page at: https://mynikohomecontrol.niko.eu/nlbe/ConnectedServices/Overview or you can use a touchscreen profile. Touchscreen profiles can be create in the 'Niko Home Control programming software' under Dashboard > Touchscreens.", "title": "Connect to your Niko Connected Controller II", "data": { "username": "Profile", @@ -16,18 +16,24 @@ "data": { "host": "Controller" } + }, + "manual_host": { + "description": "Provide a host or IP address", + "title": "Niko Connected Controller II", + "data": { + "host": "Address/IP" + } + }, + "abort": { + "single_instance_allowed": "Controller and profile already added.", + "no_controller_found": "No controller was found." + }, + "error": { + "login_check_fail_1": "Connection refused - incorrect protocol version", + "login_check_fail_2": "Connection refused - invalid client identifier", + "login_check_fail_3": "Connection refused - server unavailable", + "login_check_fail_4": "Connection refused - bad username or password", + "login_check_fail_5": "Connection refused - not authorised" } - }, - "abort": { - "single_instance_allowed": "Controller and profile already added.", - "no_controller_found": "No controller was found." - }, - "error": { - "login_check_fail_1": "Connection refused - incorrect protocol version", - "login_check_fail_2": "Connection refused - invalid client identifier", - "login_check_fail_3": "Connection refused - server unavailable", - "login_check_fail_4": "Connection refused - bad username or password", - "login_check_fail_5": "Connection refused - not authorised" } - } -} \ No newline at end of file + } \ No newline at end of file diff --git a/custom_components/nhc2/translations/en.json b/custom_components/nhc2/translations/en.json index 0edc38ed..b2e83f6f 100644 --- a/custom_components/nhc2/translations/en.json +++ b/custom_components/nhc2/translations/en.json @@ -2,7 +2,7 @@ "config": { "step": { "user": { - "description": "Configuring controller {host} ({address}).\n One option is to activate the 'Niko Hobby API' on the Connected Services page at: https://mynikohomecontrol.niko.eu/nlbe/ConnectedServices/Overview or you can use a touchscreen profile. Touchscreen profiles can be create in the 'Niko Home Control programming software' under Dashboard > Touchscreens.", + "description": "Configuring controller {host}.\n One option is to activate the 'Niko Hobby API' on the Connected Services page at: https://mynikohomecontrol.niko.eu/nlbe/ConnectedServices/Overview or you can use a touchscreen profile. Touchscreen profiles can be create in the 'Niko Home Control programming software' under Dashboard > Touchscreens.", "title": "Connect to your Niko Connected Controller II", "data": { "username": "Profile", @@ -15,6 +15,13 @@ "title": "Choose a Niko Connected Controller II", "data": { "host": "Controller" + }, + "manual_host": { + "description": "Provide a host or IP address", + "title": "Niko Connected Controller II", + "data": { + "host": "Address/IP" + } } } }, diff --git a/custom_components/nhc2/translations/nl.json b/custom_components/nhc2/translations/nl.json index 01c05488..4c685e09 100644 --- a/custom_components/nhc2/translations/nl.json +++ b/custom_components/nhc2/translations/nl.json @@ -2,7 +2,7 @@ "config": { "step": { "user": { - "description": "Configureren controller {host} ({address}).\n Een optie is het activeren van de 'Niko Hobby API' op de Geconnecteerde services pagina: https://mynikohomecontrol.niko.eu/nlbe/ConnectedServices/Overview of je gebruikt een touchscreen profiel. Touchsceen profielen kunnen aangemaakt worden in de 'Niko Home Control programming software' onder Dashboard > Touchscreens", + "description": "Configureren controller {host}.\n Een optie is het activeren van de 'Niko Hobby API' op de Geconnecteerde services pagina: https://mynikohomecontrol.niko.eu/nlbe/ConnectedServices/Overview of je gebruikt een touchscreen profiel. Touchsceen profielen kunnen aangemaakt worden in de 'Niko Home Control programming software' onder Dashboard > Touchscreens", "title": "Verbinden met je Niko Connected Controller II", "data": { "username": "Profiel", @@ -16,6 +16,13 @@ "data": { "host": "Controller" } + }, + "manual_host": { + "description": "Geef een host- of IP-adres op", + "title": "Niko Connected Controller II", + "data": { + "host": "Adres/IP" + } } }, "abort": {