From a94764348989d41292403cc57e744e26f0b4b93a Mon Sep 17 00:00:00 2001 From: Hrvoje Seketa Date: Fri, 26 Aug 2022 18:40:23 +0000 Subject: [PATCH 1/2] changing constants to use const.py from core --- .../components/konnected/__init__.py | 12 ++-- .../components/konnected/binary_sensor.py | 4 +- .../components/konnected/config_flow.py | 59 ++++++++++--------- .../components/konnected/handlers.py | 16 +++-- homeassistant/components/konnected/panel.py | 31 +++++----- homeassistant/components/konnected/sensor.py | 12 ++-- homeassistant/components/konnected/switch.py | 3 +- 7 files changed, 75 insertions(+), 62 deletions(-) diff --git a/homeassistant/components/konnected/__init__.py b/homeassistant/components/konnected/__init__.py index 620ed12ac54f1e..9f0e0e74eb263f 100644 --- a/homeassistant/components/konnected/__init__.py +++ b/homeassistant/components/konnected/__init__.py @@ -14,11 +14,12 @@ from homeassistant.components.http import HomeAssistantView from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ATTR_ENTITY_ID, CONF_ACCESS_TOKEN, CONF_BINARY_SENSORS, + CONF_DEVICE_ID, CONF_DEVICES, CONF_DISCOVERY, + CONF_ENTITY_ID, CONF_HOST, CONF_ID, CONF_NAME, @@ -26,6 +27,7 @@ CONF_PORT, CONF_REPEAT, CONF_SENSORS, + CONF_STATE, CONF_SWITCHES, CONF_TYPE, CONF_ZONE, @@ -365,7 +367,7 @@ async def update_sensor(self, request: Request, device_id) -> Response: "unregistered sensor/actuator", status_code=HTTPStatus.BAD_REQUEST ) - zone_data["device_id"] = device_id + zone_data[CONF_DEVICE_ID] = device_id for attr in ("state", "temp", "humi", "addr"): value = payload.get(attr) @@ -423,14 +425,14 @@ async def get(self, request: Request, device_id) -> Response: resp[CONF_PIN] = ZONE_TO_PIN[zone_num] # Make sure entity is setup - if zone_entity_id := zone.get(ATTR_ENTITY_ID): - resp["state"] = self.binary_value( + if zone_entity_id := zone.get(CONF_ENTITY_ID): + resp[CONF_STATE] = self.binary_value( hass.states.get(zone_entity_id).state, zone[CONF_ACTIVATION] ) return self.json(resp) _LOGGER.warning("Konnected entity not yet setup, returning default") - resp["state"] = self.binary_value(STATE_OFF, zone[CONF_ACTIVATION]) + resp[CONF_STATE] = self.binary_value(STATE_OFF, zone[CONF_ACTIVATION]) return self.json(resp) async def put(self, request: Request, device_id) -> Response: diff --git a/homeassistant/components/konnected/binary_sensor.py b/homeassistant/components/konnected/binary_sensor.py index 307c8bc24a714c..f88f15747003e3 100644 --- a/homeassistant/components/konnected/binary_sensor.py +++ b/homeassistant/components/konnected/binary_sensor.py @@ -2,10 +2,10 @@ from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ATTR_ENTITY_ID, ATTR_STATE, CONF_BINARY_SENSORS, CONF_DEVICES, + CONF_ENTITY_ID, CONF_NAME, CONF_TYPE, ) @@ -81,7 +81,7 @@ def device_info(self) -> DeviceInfo: async def async_added_to_hass(self): """Store entity_id and register state change callback.""" - self._data[ATTR_ENTITY_ID] = self.entity_id + self._data[CONF_ENTITY_ID] = self.entity_id self.async_on_remove( async_dispatcher_connect( self.hass, f"konnected.{self.entity_id}.update", self.async_set_state diff --git a/homeassistant/components/konnected/config_flow.py b/homeassistant/components/konnected/config_flow.py index fcf94a38c18add..761a507c71cd6d 100644 --- a/homeassistant/components/konnected/config_flow.py +++ b/homeassistant/components/konnected/config_flow.py @@ -19,15 +19,18 @@ ) from homeassistant.const import ( CONF_ACCESS_TOKEN, + CONF_BASE, CONF_BINARY_SENSORS, CONF_DISCOVERY, CONF_HOST, CONF_ID, + CONF_MAC, CONF_MODEL, CONF_NAME, CONF_PORT, CONF_REPEAT, CONF_SENSORS, + CONF_STATE, CONF_SWITCHES, CONF_TYPE, CONF_ZONE, @@ -188,11 +191,11 @@ async def async_gen_config(self, host, port): self.data[CONF_PORT] = port try: status = await get_status(self.hass, host, port) - self.data[CONF_ID] = status.get("chipId", status["mac"].replace(":", "")) + self.data[CONF_ID] = status.get("chipId", status[CONF_MAC].replace(":", "")) except (CannotConnect, KeyError) as err: raise CannotConnect from err else: - self.data[CONF_MODEL] = status.get("model", KONN_MODEL) + self.data[CONF_MODEL] = status.get(CONF_MODEL, KONN_MODEL) self.data[CONF_ACCESS_TOKEN] = "".join( random.choices(f"{string.ascii_uppercase}{string.digits}", k=20) ) @@ -286,9 +289,9 @@ async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowRes self.data[CONF_HOST] = netloc[0] self.data[CONF_PORT] = int(netloc[1]) self.data[CONF_ID] = status.get( - "chipId", status["mac"].replace(":", "") + "chipId", status[CONF_MAC].replace(":", "") ) - self.data[CONF_MODEL] = status.get("model", KONN_MODEL) + self.data[CONF_MODEL] = status.get(CONF_MODEL, KONN_MODEL) KonnectedFlowHandler.discovered_hosts[self.data[CONF_ID]] = { CONF_HOST: self.data[CONF_HOST], @@ -313,12 +316,12 @@ async def async_step_user(self, user_input=None): self.hass, self.data[CONF_HOST], self.data[CONF_PORT] ) except CannotConnect: - errors["base"] = "cannot_connect" + errors[CONF_BASE] = "cannot_connect" else: self.data[CONF_ID] = status.get( - "chipId", status["mac"].replace(":", "") + "chipId", status[CONF_MAC].replace(":", "") ) - self.data[CONF_MODEL] = status.get("model", KONN_MODEL) + self.data[CONF_MODEL] = status.get(CONF_MODEL, KONN_MODEL) # save off our discovered host info KonnectedFlowHandler.discovered_hosts[self.data[CONF_ID]] = { @@ -330,8 +333,8 @@ async def async_step_user(self, user_input=None): return self.async_show_form( step_id="user", description_placeholders={ - "host": self.data.get(CONF_HOST, "Unknown"), - "port": self.data.get(CONF_PORT, "Unknown"), + CONF_HOST: self.data.get(CONF_HOST, "Unknown"), + CONF_PORT: self.data.get(CONF_PORT, "Unknown"), }, data_schema=vol.Schema( { @@ -357,10 +360,10 @@ async def async_step_confirm(self, user_input=None): return self.async_show_form( step_id="confirm", description_placeholders={ - "model": KONN_PANEL_MODEL_NAMES[self.data[CONF_MODEL]], - "id": self.unique_id, - "host": self.data[CONF_HOST], - "port": self.data[CONF_PORT], + CONF_MODEL: KONN_PANEL_MODEL_NAMES[self.data[CONF_MODEL]], + CONF_ID: self.unique_id, + CONF_HOST: self.data[CONF_HOST], + CONF_PORT: self.data[CONF_PORT], }, ) @@ -457,8 +460,8 @@ async def async_step_options_io(self, user_input=None): } ), description_placeholders={ - "model": KONN_PANEL_MODEL_NAMES[self.model], - "host": self.entry.data[CONF_HOST], + CONF_MODEL: KONN_PANEL_MODEL_NAMES[self.model], + CONF_HOST: self.entry.data[CONF_HOST], }, errors=errors, ) @@ -493,8 +496,8 @@ async def async_step_options_io(self, user_input=None): } ), description_placeholders={ - "model": KONN_PANEL_MODEL_NAMES[self.model], - "host": self.entry.data[CONF_HOST], + CONF_MODEL: KONN_PANEL_MODEL_NAMES[self.model], + CONF_HOST: self.entry.data[CONF_HOST], }, errors=errors, ) @@ -551,8 +554,8 @@ async def async_step_options_io_ext(self, user_input=None): } ), description_placeholders={ - "model": KONN_PANEL_MODEL_NAMES[self.model], - "host": self.entry.data[CONF_HOST], + CONF_MODEL: KONN_PANEL_MODEL_NAMES[self.model], + CONF_HOST: self.entry.data[CONF_HOST], }, errors=errors, ) @@ -592,7 +595,7 @@ async def async_step_options_binary(self, user_input=None): } ), description_placeholders={ - "zone": f"Zone {self.active_cfg}" + CONF_ZONE: f"Zone {self.active_cfg}" if len(self.active_cfg) < 3 else self.active_cfg.upper }, @@ -663,7 +666,7 @@ async def async_step_options_digital(self, user_input=None): } ), description_placeholders={ - "zone": f"Zone {self.active_cfg}" + CONF_ZONE: f"Zone {self.active_cfg}" if len(self.active_cfg) < 3 else self.active_cfg.upper() }, @@ -693,7 +696,7 @@ async def async_step_options_digital(self, user_input=None): } ), description_placeholders={ - "zone": f"Zone {self.active_cfg}" + CONF_ZONE: f"Zone {self.active_cfg}" if len(self.active_cfg) < 3 else self.active_cfg.upper() }, @@ -706,7 +709,7 @@ async def async_step_options_switch(self, user_input=None): """Allow the user to configure the IO options for switches.""" errors = {} if user_input is not None: - zone = {"zone": self.active_cfg} + zone = {CONF_ZONE: self.active_cfg} zone.update(user_input) del zone[CONF_MORE_STATES] self.new_opt[CONF_SWITCHES] = self.new_opt.get(CONF_SWITCHES, []) + [zone] @@ -755,10 +758,10 @@ async def async_step_options_switch(self, user_input=None): } ), description_placeholders={ - "zone": f"Zone {self.active_cfg}" + CONF_ZONE: f"Zone {self.active_cfg}" if len(self.active_cfg) < 3 else self.active_cfg.upper(), - "state": str(self.current_state), + CONF_STATE: str(self.current_state), }, errors=errors, ) @@ -807,10 +810,10 @@ async def async_step_options_switch(self, user_input=None): } ), description_placeholders={ - "zone": f"Zone {self.active_cfg}" + CONF_ZONE: f"Zone {self.active_cfg}" if len(self.active_cfg) < 3 else self.active_cfg.upper(), - "state": str(self.current_state), + CONF_STATE: str(self.current_state), }, errors=errors, ) @@ -828,7 +831,7 @@ async def async_step_options_misc(self, user_input=None): else: user_input[CONF_API_HOST] = "" except vol.Invalid: - errors["base"] = "bad_host" + errors[CONF_BASE] = "bad_host" else: # no need to store the override - can infer del user_input[CONF_OVERRIDE_API_HOST] diff --git a/homeassistant/components/konnected/handlers.py b/homeassistant/components/konnected/handlers.py index af784750627a78..afaf846b9dcbe7 100644 --- a/homeassistant/components/konnected/handlers.py +++ b/homeassistant/components/konnected/handlers.py @@ -2,7 +2,13 @@ import logging from homeassistant.components.sensor import SensorDeviceClass -from homeassistant.const import ATTR_ENTITY_ID, ATTR_STATE +from homeassistant.const import ( + ATTR_DEVICE_ID, + ATTR_STATE, + ATTR_TEMPERATURE, + CONF_ENTITY_ID, + CONF_STATE, +) from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.util import decorator @@ -12,11 +18,11 @@ HANDLERS = decorator.Registry() # type: ignore[var-annotated] -@HANDLERS.register("state") +@HANDLERS.register(CONF_STATE) async def async_handle_state_update(hass, context, msg): """Handle a binary sensor or switch state update.""" _LOGGER.debug("[state handler] context: %s msg: %s", context, msg) - entity_id = context.get(ATTR_ENTITY_ID) + entity_id = context.get(CONF_ENTITY_ID) state = bool(int(msg.get(ATTR_STATE))) if context.get(CONF_INVERSE): state = not state @@ -50,7 +56,7 @@ async def async_handle_addr_update(hass, context, msg): if entity_id := context.get(addr): async_dispatcher_send(hass, f"konnected.{entity_id}.update", temp) else: - msg["device_id"] = context.get("device_id") - msg["temperature"] = temp + msg[ATTR_DEVICE_ID] = context.get(ATTR_DEVICE_ID) + msg[ATTR_TEMPERATURE] = temp msg["addr"] = addr async_dispatcher_send(hass, SIGNAL_DS18B20_NEW, msg) diff --git a/homeassistant/components/konnected/panel.py b/homeassistant/components/konnected/panel.py index 2c7b57449b7088..16dc77c45e853e 100644 --- a/homeassistant/components/konnected/panel.py +++ b/homeassistant/components/konnected/panel.py @@ -5,19 +5,20 @@ import konnected from homeassistant.const import ( - ATTR_ENTITY_ID, - ATTR_STATE, CONF_ACCESS_TOKEN, CONF_BINARY_SENSORS, CONF_DEVICES, CONF_DISCOVERY, + CONF_ENTITY_ID, CONF_HOST, CONF_ID, + CONF_MODEL, CONF_NAME, CONF_PIN, CONF_PORT, CONF_REPEAT, CONF_SENSORS, + CONF_STATE, CONF_SWITCHES, CONF_TYPE, CONF_ZONE, @@ -120,7 +121,7 @@ async def async_connect(self, now=None): ) self.status = await self.client.get_status() self.api_version = KONN_API_VERSIONS.get( - self.status.get("model", KONN_MODEL), KONN_API_VERSIONS[KONN_MODEL] + self.status.get(CONF_MODEL, KONN_MODEL), KONN_API_VERSIONS[KONN_MODEL] ) _LOGGER.info( "Connected to new %s device", self.status.get("model", "Konnected") @@ -202,12 +203,12 @@ async def async_save_data(self): CONF_NAME, f"Konnected {self.device_id[6:]} Zone {zone}" ), CONF_INVERSE: entity.get(CONF_INVERSE), - ATTR_STATE: None, + CONF_STATE: None, } _LOGGER.debug( "Set up binary_sensor %s (initial state: %s)", - binary_sensors[zone].get("name"), - binary_sensors[zone].get(ATTR_STATE), + binary_sensors[zone].get(CONF_NAME), + binary_sensors[zone].get(CONF_STATE), ) actuators = [] @@ -220,7 +221,7 @@ async def async_save_data(self): CONF_NAME, f"Konnected {self.device_id[6:]} Actuator {zone}", ), - ATTR_STATE: None, + CONF_STATE: None, CONF_ACTIVATION: entity[CONF_ACTIVATION], CONF_MOMENTARY: entity.get(CONF_MOMENTARY), CONF_PAUSE: entity.get(CONF_PAUSE), @@ -246,7 +247,7 @@ async def async_save_data(self): "Set up %s sensor %s (initial state: %s)", sensor.get(CONF_TYPE), sensor.get(CONF_NAME), - sensor.get(ATTR_STATE), + sensor.get(CONF_STATE), ) device_data = { @@ -318,9 +319,9 @@ async def async_update_initial_states(self): sensor_config = self.stored_configuration[CONF_BINARY_SENSORS].get( sensor_data.get(CONF_ZONE, sensor_data.get(CONF_PIN)), {} ) - entity_id = sensor_config.get(ATTR_ENTITY_ID) + entity_id = sensor_config.get(CONF_ENTITY_ID) - state = bool(sensor_data.get(ATTR_STATE)) + state = bool(sensor_data.get(CONF_STATE)) if sensor_config.get(CONF_INVERSE): state = not state @@ -337,14 +338,14 @@ def async_desired_settings_payload(self): desired_api_endpoint = desired_api_host + ENDPOINT_ROOT return { - "sensors": self.async_binary_sensor_configuration(), + CONF_SENSORS: self.async_binary_sensor_configuration(), "actuators": self.async_actuator_configuration(), "dht_sensors": self.async_dht_sensor_configuration(), "ds18b20_sensors": self.async_ds18b20_sensor_configuration(), "auth_token": self.config.get(CONF_ACCESS_TOKEN), "endpoint": desired_api_endpoint, "blink": self.options.get(CONF_BLINK, True), - "discovery": self.options.get(CONF_DISCOVERY, True), + CONF_DISCOVERY: self.options.get(CONF_DISCOVERY, True), } @callback @@ -353,9 +354,9 @@ def async_current_settings_payload(self): settings = self.status["settings"] or {} return { - "sensors": [ + CONF_SENSORS: [ {self.api_version: s[self.api_version]} - for s in self.status.get("sensors") + for s in self.status.get(CONF_SENSORS) ], "actuators": self.status.get("actuators"), "dht_sensors": self.status.get(CONF_DHT_SENSORS), @@ -363,7 +364,7 @@ def async_current_settings_payload(self): "auth_token": settings.get("token"), "endpoint": settings.get("endpoint"), "blink": settings.get(CONF_BLINK), - "discovery": settings.get(CONF_DISCOVERY), + CONF_DISCOVERY: settings.get(CONF_DISCOVERY), } async def async_sync_device_config(self): diff --git a/homeassistant/components/konnected/sensor.py b/homeassistant/components/konnected/sensor.py index 3bd3a05c60909a..2e444a651917fe 100644 --- a/homeassistant/components/konnected/sensor.py +++ b/homeassistant/components/konnected/sensor.py @@ -24,14 +24,14 @@ from .const import DOMAIN as KONNECTED_DOMAIN, SIGNAL_DS18B20_NEW SENSOR_TYPES: dict[str, SensorEntityDescription] = { - "temperature": SensorEntityDescription( - key="temperature", + SensorDeviceClass.TEMPERATURE: SensorEntityDescription( + key=SensorDeviceClass.TEMPERATURE, name="Temperature", native_unit_of_measurement=TEMP_CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, ), - "humidity": SensorEntityDescription( - key="humidity", + SensorDeviceClass.HUMIDITY: SensorEntityDescription( + key=SensorDeviceClass.HUMIDITY, name="Humidity", native_unit_of_measurement=PERCENTAGE, device_class=SensorDeviceClass.HUMIDITY, @@ -79,7 +79,7 @@ def async_add_ds18b20(attrs): KonnectedSensor( device_id, sensor_config, - SENSOR_TYPES["temperature"], + SENSOR_TYPES[SensorDeviceClass.TEMPERATURE], addr=attrs.get("addr"), initial_state=attrs.get("temp"), ) @@ -138,7 +138,7 @@ async def async_added_to_hass(self): @callback def async_set_state(self, state): """Update the sensor's state.""" - if self.entity_description.key == "humidity": + if self.entity_description.key == SensorDeviceClass.HUMIDITY: self._state = int(float(state)) else: self._state = round(float(state), 1) diff --git a/homeassistant/components/konnected/switch.py b/homeassistant/components/konnected/switch.py index 123c5b94ab45ad..a36585e922996c 100644 --- a/homeassistant/components/konnected/switch.py +++ b/homeassistant/components/konnected/switch.py @@ -6,6 +6,7 @@ from homeassistant.const import ( ATTR_STATE, CONF_DEVICES, + CONF_ENTITY_ID, CONF_NAME, CONF_REPEAT, CONF_SWITCHES, @@ -144,7 +145,7 @@ def async_set_state(self, state): async def async_added_to_hass(self): """Store entity_id and register state change callback.""" - self._data["entity_id"] = self.entity_id + self._data[CONF_ENTITY_ID] = self.entity_id self.async_on_remove( async_dispatcher_connect( self.hass, f"konnected.{self.entity_id}.update", self.async_set_state From 9cfcc0fcbd6d957287ed2ed2cf7dcfe90d4fde95 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 20 Sep 2022 07:41:20 +0000 Subject: [PATCH 2/2] Bump codecov/codecov-action from 3.1.0 to 3.1.1 Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3.1.0 to 3.1.1. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/master/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v3.1.0...v3.1.1) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 75a200402d680a..2acff92d026806 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -839,9 +839,9 @@ jobs: uses: actions/download-artifact@v3 - name: Upload coverage to Codecov (full coverage) if: needs.info.outputs.test_full_suite == 'true' - uses: codecov/codecov-action@v3.1.0 + uses: codecov/codecov-action@v3.1.1 with: flags: full-suite - name: Upload coverage to Codecov (partial coverage) if: needs.info.outputs.test_full_suite == 'false' - uses: codecov/codecov-action@v3.1.0 + uses: codecov/codecov-action@v3.1.1