Skip to content

Commit

Permalink
address renamed to mac
Browse files Browse the repository at this point in the history
  • Loading branch information
dudanov committed Jul 18, 2024
1 parent de45b71 commit 0bb193d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
12 changes: 6 additions & 6 deletions custom_components/ftms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand Down Expand Up @@ -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,
)
)
Expand Down
12 changes: 6 additions & 6 deletions custom_components/ftms/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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")
Expand Down Expand Up @@ -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()

Expand All @@ -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)

Expand Down Expand Up @@ -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]},
)

Expand Down
3 changes: 2 additions & 1 deletion custom_components/ftms/connect.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from bleak.exc import BleakError
from homeassistant.const import CONF_MAC
from homeassistant.exceptions import ConfigEntryNotReady
from pyftms import FitnessMachine

Expand All @@ -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
4 changes: 2 additions & 2 deletions custom_components/ftms/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}."
}
}
}
4 changes: 2 additions & 2 deletions custom_components/ftms/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@
},
"exceptions": {
"device_not_found": {
"message": "Bluetooth устройство {address} не найдено."
"message": "Bluetooth устройство {mac} не найдено."
},
"connection_failed": {
"message": "Ошибка соединения с Bluetooth устройством {address}."
"message": "Ошибка соединения с Bluetooth устройством {mac}."
}
}
}

0 comments on commit 0bb193d

Please sign in to comment.