diff --git a/custom_components/ftms/__init__.py b/custom_components/ftms/__init__.py index 37df0f8..e5f1a7c 100644 --- a/custom_components/ftms/__init__.py +++ b/custom_components/ftms/__init__.py @@ -7,7 +7,7 @@ from homeassistant.components.bluetooth.match import BluetoothCallbackMatcher from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - CONF_ADDRESS, + CONF_MAC, CONF_SENSORS, EVENT_HOMEASSISTANT_STOP, Platform, @@ -45,12 +45,12 @@ async def async_unload_entry(hass: HomeAssistant, entry: FtmsConfigEntry) -> boo async def async_setup_entry(hass: HomeAssistant, entry: FtmsConfigEntry) -> bool: """Set up device from a config entry.""" - address: str = entry.data[CONF_ADDRESS] + mac: str = entry.data[CONF_MAC] - if not (srv_info := bluetooth.async_last_service_info(hass, address)): + if not (srv_info := bluetooth.async_last_service_info(hass, mac)): raise ConfigEntryNotReady( translation_key="device_not_found", - translation_placeholders={"address": address}, + translation_placeholders={"address": mac}, ) def _on_disconnect(ftms_: pyftms.FitnessMachine) -> None: @@ -68,7 +68,7 @@ def _on_disconnect(ftms_: pyftms.FitnessMachine) -> None: assert ftms.machine_type.name unique_id = "".join( - x.lower() for x in ftms.device_info.get("serial_number", address) if x.isalnum() + x.lower() for x in ftms.device_info.get("serial_number", mac) if x.isalnum() ) device_info = dr.DeviceInfo( @@ -101,7 +101,7 @@ def _async_on_ble_event( bluetooth.async_register_callback( hass, _async_on_ble_event, - BluetoothCallbackMatcher(address=address), + BluetoothCallbackMatcher(address=mac), bluetooth.BluetoothScanningMode.ACTIVE, ) ) diff --git a/custom_components/ftms/config_flow.py b/custom_components/ftms/config_flow.py index 3a2f98b..4cd495f 100644 --- a/custom_components/ftms/config_flow.py +++ b/custom_components/ftms/config_flow.py @@ -20,7 +20,7 @@ OptionsFlow, OptionsFlowWithConfigEntry, ) -from homeassistant.const import CONF_ADDRESS, CONF_DISCOVERY, CONF_SENSORS +from homeassistant.const import CONF_DISCOVERY, CONF_MAC, CONF_SENSORS from homeassistant.core import callback from homeassistant.helpers.selector import selector from pyftms import ( @@ -47,7 +47,7 @@ async def async_step_init( if user_input is not None: return self.async_create_entry(title="", data=user_input) - address = self.config_entry.data[CONF_ADDRESS] + address = self.config_entry.data[CONF_MAC] if not (srv_info := async_last_service_info(self.hass, address)): return self.async_abort(reason="no_devices_found") @@ -111,8 +111,8 @@ async def async_step_user( """Handle the user step to pick discovered device.""" if user_input is not None: - address = user_input[CONF_ADDRESS] - self._ble_info = self._discovered_devices[address] + mac = user_input[CONF_MAC] + self._ble_info = self._discovered_devices[mac] return await self.async_step_confirm() @@ -137,7 +137,7 @@ async def async_step_user( for mac, dev in self._discovered_devices.items() } - schema = vol.Schema({vol.Required(CONF_ADDRESS): vol.In(devices)}) + schema = vol.Schema({vol.Required(CONF_MAC): vol.In(devices)}) return self.async_show_form(step_id="user", data_schema=schema) @@ -265,7 +265,7 @@ async def async_step_information(self, user_input=None): return self.async_create_entry( title=" ".join((s1, s2, s3)), - data={CONF_ADDRESS: self._ftms.address}, + data={CONF_MAC: self._ftms.address}, options={CONF_SENSORS: user_input[CONF_SENSORS]}, ) diff --git a/custom_components/ftms/connect.py b/custom_components/ftms/connect.py index e15ac4d..21e94a8 100644 --- a/custom_components/ftms/connect.py +++ b/custom_components/ftms/connect.py @@ -1,4 +1,5 @@ from bleak.exc import BleakError +from homeassistant.const import CONF_MAC from homeassistant.exceptions import ConfigEntryNotReady from pyftms import FitnessMachine @@ -9,5 +10,5 @@ async def ftms_connect(ftms: FitnessMachine): except BleakError as exc: raise ConfigEntryNotReady( translation_key="connection_failed", - translation_placeholders={"address": ftms.address}, + translation_placeholders={CONF_MAC: ftms.address}, ) from exc diff --git a/custom_components/ftms/translations/en.json b/custom_components/ftms/translations/en.json index 5f2a3e3..9f5bf6a 100644 --- a/custom_components/ftms/translations/en.json +++ b/custom_components/ftms/translations/en.json @@ -241,10 +241,10 @@ }, "exceptions": { "device_not_found": { - "message": "Bluetooth device {address} not found." + "message": "Bluetooth device {mac} not found." }, "connection_failed": { - "message": "Failed connect to Bluetooth device {address}." + "message": "Failed connect to Bluetooth device {mac}." } } } \ No newline at end of file diff --git a/custom_components/ftms/translations/ru.json b/custom_components/ftms/translations/ru.json index 512340a..e33fe38 100644 --- a/custom_components/ftms/translations/ru.json +++ b/custom_components/ftms/translations/ru.json @@ -241,10 +241,10 @@ }, "exceptions": { "device_not_found": { - "message": "Bluetooth устройство {address} не найдено." + "message": "Bluetooth устройство {mac} не найдено." }, "connection_failed": { - "message": "Ошибка соединения с Bluetooth устройством {address}." + "message": "Ошибка соединения с Bluetooth устройством {mac}." } } } \ No newline at end of file