diff --git a/homeassistant/components/onewire/binary_sensor.py b/homeassistant/components/onewire/binary_sensor.py index 9671a787c41eb..5b73a8c8873b3 100644 --- a/homeassistant/components/onewire/binary_sensor.py +++ b/homeassistant/components/onewire/binary_sensor.py @@ -5,7 +5,13 @@ from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_TYPE +from homeassistant.const import ( + ATTR_IDENTIFIERS, + ATTR_MANUFACTURER, + ATTR_MODEL, + ATTR_NAME, + CONF_TYPE, +) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -113,10 +119,10 @@ def get_entities(onewirehub: OneWireHub) -> list[OneWireBaseEntity]: if family not in DEVICE_BINARY_SENSORS: continue device_info: DeviceInfo = { - "identifiers": {(DOMAIN, device_id)}, - "manufacturer": "Maxim Integrated", - "model": device_type, - "name": device_id, + ATTR_IDENTIFIERS: {(DOMAIN, device_id)}, + ATTR_MANUFACTURER: "Maxim Integrated", + ATTR_MODEL: device_type, + ATTR_NAME: device_id, } for entity_specs in DEVICE_BINARY_SENSORS[family]: entity_path = os.path.join( diff --git a/homeassistant/components/onewire/sensor.py b/homeassistant/components/onewire/sensor.py index 97291f0bbccd3..024d540c10ad1 100644 --- a/homeassistant/components/onewire/sensor.py +++ b/homeassistant/components/onewire/sensor.py @@ -11,7 +11,13 @@ from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_TYPE +from homeassistant.const import ( + ATTR_IDENTIFIERS, + ATTR_MANUFACTURER, + ATTR_MODEL, + ATTR_NAME, + CONF_TYPE, +) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -288,10 +294,10 @@ def get_entities( ) continue device_info: DeviceInfo = { - "identifiers": {(DOMAIN, device_id)}, - "manufacturer": "Maxim Integrated", - "model": device_type, - "name": device_id, + ATTR_IDENTIFIERS: {(DOMAIN, device_id)}, + ATTR_MANUFACTURER: "Maxim Integrated", + ATTR_MODEL: device_type, + ATTR_NAME: device_id, } for entity_specs in get_sensor_types(device_sub_type)[family]: if entity_specs["type"] == SENSOR_TYPE_MOISTURE: @@ -334,10 +340,10 @@ def get_entities( continue device_info = { - "identifiers": {(DOMAIN, sensor_id)}, - "manufacturer": "Maxim Integrated", - "model": family, - "name": sensor_id, + ATTR_IDENTIFIERS: {(DOMAIN, sensor_id)}, + ATTR_MANUFACTURER: "Maxim Integrated", + ATTR_MODEL: family, + ATTR_NAME: sensor_id, } device_file = f"/sys/bus/w1/devices/{sensor_id}/w1_slave" entities.append( diff --git a/homeassistant/components/onewire/switch.py b/homeassistant/components/onewire/switch.py index 228c8f9d78bf3..b5177bfca15ed 100644 --- a/homeassistant/components/onewire/switch.py +++ b/homeassistant/components/onewire/switch.py @@ -7,7 +7,13 @@ from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import CONF_TYPE +from homeassistant.const import ( + ATTR_IDENTIFIERS, + ATTR_MANUFACTURER, + ATTR_MODEL, + ATTR_NAME, + CONF_TYPE, +) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -186,10 +192,10 @@ def get_entities(onewirehub: OneWireHub) -> list[OneWireBaseEntity]: continue device_info: DeviceInfo = { - "identifiers": {(DOMAIN, device_id)}, - "manufacturer": "Maxim Integrated", - "model": device_type, - "name": device_id, + ATTR_IDENTIFIERS: {(DOMAIN, device_id)}, + ATTR_MANUFACTURER: "Maxim Integrated", + ATTR_MODEL: device_type, + ATTR_NAME: device_id, } for entity_specs in DEVICE_SWITCHES[family]: entity_path = os.path.join( diff --git a/tests/components/onewire/const.py b/tests/components/onewire/const.py index 5c12571fc1ef4..8a20d4fb0aa1b 100644 --- a/tests/components/onewire/const.py +++ b/tests/components/onewire/const.py @@ -8,6 +8,10 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN from homeassistant.const import ( + ATTR_IDENTIFIERS, + ATTR_MANUFACTURER, + ATTR_MODEL, + ATTR_NAME, DEVICE_CLASS_CURRENT, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, @@ -24,6 +28,8 @@ TEMP_CELSIUS, ) +MANUFACTURER = "Maxim Integrated" + MOCK_OWPROXY_DEVICES = { "00.111111111111": { "inject_reads": [ @@ -36,10 +42,10 @@ b"DS2405", # read device type ], "device_info": { - "identifiers": {(DOMAIN, "05.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "DS2405", - "name": "05.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "05.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "DS2405", + ATTR_NAME: "05.111111111111", }, SWITCH_DOMAIN: [ { @@ -58,10 +64,10 @@ b"DS18S20", # read device type ], "device_info": { - "identifiers": {(DOMAIN, "10.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "DS18S20", - "name": "10.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "10.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "DS18S20", + ATTR_NAME: "10.111111111111", }, SENSOR_DOMAIN: [ { @@ -79,10 +85,10 @@ b"DS2406", # read device type ], "device_info": { - "identifiers": {(DOMAIN, "12.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "DS2406", - "name": "12.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "12.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "DS2406", + ATTR_NAME: "12.111111111111", }, BINARY_SENSOR_DOMAIN: [ { @@ -168,10 +174,10 @@ b"DS2423", # read device type ], "device_info": { - "identifiers": {(DOMAIN, "1D.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "DS2423", - "name": "1D.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "1D.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "DS2423", + ATTR_NAME: "1D.111111111111", }, SENSOR_DOMAIN: [ { @@ -197,10 +203,10 @@ b"DS2409", # read device type ], "device_info": { - "identifiers": {(DOMAIN, "1F.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "DS2409", - "name": "1F.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "1F.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "DS2409", + ATTR_NAME: "1F.111111111111", }, "branches": { "aux": {}, @@ -210,10 +216,10 @@ b"DS2423", # read device type ], "device_info": { - "identifiers": {(DOMAIN, "1D.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "DS2423", - "name": "1D.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "1D.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "DS2423", + ATTR_NAME: "1D.111111111111", }, SENSOR_DOMAIN: [ { @@ -244,10 +250,10 @@ b"DS1822", # read device type ], "device_info": { - "identifiers": {(DOMAIN, "22.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "DS1822", - "name": "22.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "22.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "DS1822", + ATTR_NAME: "22.111111111111", }, SENSOR_DOMAIN: [ { @@ -265,10 +271,10 @@ b"DS2438", # read device type ], "device_info": { - "identifiers": {(DOMAIN, "26.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "DS2438", - "name": "26.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "26.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "DS2438", + ATTR_NAME: "26.111111111111", }, SENSOR_DOMAIN: [ { @@ -376,10 +382,10 @@ b"DS18B20", # read device type ], "device_info": { - "identifiers": {(DOMAIN, "28.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "DS18B20", - "name": "28.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "28.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "DS18B20", + ATTR_NAME: "28.111111111111", }, SENSOR_DOMAIN: [ { @@ -397,10 +403,10 @@ b"DS2408", # read device type ], "device_info": { - "identifiers": {(DOMAIN, "29.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "DS2408", - "name": "29.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "29.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "DS2408", + ATTR_NAME: "29.111111111111", }, BINARY_SENSOR_DOMAIN: [ { @@ -628,10 +634,10 @@ b"DS1825", # read device type ], "device_info": { - "identifiers": {(DOMAIN, "3B.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "DS1825", - "name": "3B.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "3B.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "DS1825", + ATTR_NAME: "3B.111111111111", }, SENSOR_DOMAIN: [ { @@ -649,10 +655,10 @@ b"DS28EA00", # read device type ], "device_info": { - "identifiers": {(DOMAIN, "42.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "DS28EA00", - "name": "42.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "42.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "DS28EA00", + ATTR_NAME: "42.111111111111", }, SENSOR_DOMAIN: [ { @@ -670,10 +676,10 @@ b"HobbyBoards_EF", # read type ], "device_info": { - "identifiers": {(DOMAIN, "EF.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "HobbyBoards_EF", - "name": "EF.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "EF.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "HobbyBoards_EF", + ATTR_NAME: "EF.111111111111", }, SENSOR_DOMAIN: [ { @@ -711,10 +717,10 @@ b" 0", # read is_leaf_3 ], "device_info": { - "identifiers": {(DOMAIN, "EF.111111111112")}, - "manufacturer": "Maxim Integrated", - "model": "HB_MOISTURE_METER", - "name": "EF.111111111112", + ATTR_IDENTIFIERS: {(DOMAIN, "EF.111111111112")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "HB_MOISTURE_METER", + ATTR_NAME: "EF.111111111112", }, SENSOR_DOMAIN: [ { @@ -757,10 +763,10 @@ b"EDS0068", # read device_type - note EDS specific ], "device_info": { - "identifiers": {(DOMAIN, "7E.111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "EDS", - "name": "7E.111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "7E.111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "EDS", + ATTR_NAME: "7E.111111111111", }, SENSOR_DOMAIN: [ { @@ -803,10 +809,10 @@ b"EDS0066", # read device_type - note EDS specific ], "device_info": { - "identifiers": {(DOMAIN, "7E.222222222222")}, - "manufacturer": "Maxim Integrated", - "model": "EDS", - "name": "7E.222222222222", + ATTR_IDENTIFIERS: {(DOMAIN, "7E.222222222222")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "EDS", + ATTR_NAME: "7E.222222222222", }, SENSOR_DOMAIN: [ { @@ -833,10 +839,10 @@ "00-111111111111": {SENSOR_DOMAIN: []}, "10-111111111111": { "device_info": { - "identifiers": {(DOMAIN, "10-111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "10", - "name": "10-111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "10-111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "10", + ATTR_NAME: "10-111111111111", }, SENSOR_DOMAIN: [ { @@ -853,10 +859,10 @@ "1D-111111111111": {SENSOR_DOMAIN: []}, "22-111111111111": { "device_info": { - "identifiers": {(DOMAIN, "22-111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "22", - "name": "22-111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "22-111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "22", + ATTR_NAME: "22-111111111111", }, "sensor": [ { @@ -872,10 +878,10 @@ "26-111111111111": {SENSOR_DOMAIN: []}, "28-111111111111": { "device_info": { - "identifiers": {(DOMAIN, "28-111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "28", - "name": "28-111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "28-111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "28", + ATTR_NAME: "28-111111111111", }, SENSOR_DOMAIN: [ { @@ -891,10 +897,10 @@ "29-111111111111": {SENSOR_DOMAIN: []}, "3B-111111111111": { "device_info": { - "identifiers": {(DOMAIN, "3B-111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "3B", - "name": "3B-111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "3B-111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "3B", + ATTR_NAME: "3B-111111111111", }, SENSOR_DOMAIN: [ { @@ -909,10 +915,10 @@ }, "42-111111111111": { "device_info": { - "identifiers": {(DOMAIN, "42-111111111111")}, - "manufacturer": "Maxim Integrated", - "model": "42", - "name": "42-111111111111", + ATTR_IDENTIFIERS: {(DOMAIN, "42-111111111111")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "42", + ATTR_NAME: "42-111111111111", }, SENSOR_DOMAIN: [ { @@ -927,10 +933,10 @@ }, "42-111111111112": { "device_info": { - "identifiers": {(DOMAIN, "42-111111111112")}, - "manufacturer": "Maxim Integrated", - "model": "42", - "name": "42-111111111112", + ATTR_IDENTIFIERS: {(DOMAIN, "42-111111111112")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "42", + ATTR_NAME: "42-111111111112", }, SENSOR_DOMAIN: [ { @@ -945,10 +951,10 @@ }, "42-111111111113": { "device_info": { - "identifiers": {(DOMAIN, "42-111111111113")}, - "manufacturer": "Maxim Integrated", - "model": "42", - "name": "42-111111111113", + ATTR_IDENTIFIERS: {(DOMAIN, "42-111111111113")}, + ATTR_MANUFACTURER: MANUFACTURER, + ATTR_MODEL: "42", + ATTR_NAME: "42-111111111113", }, SENSOR_DOMAIN: [ { diff --git a/tests/components/onewire/test_sensor.py b/tests/components/onewire/test_sensor.py index f3f4b8e7c9d8d..77570f055b49e 100644 --- a/tests/components/onewire/test_sensor.py +++ b/tests/components/onewire/test_sensor.py @@ -10,6 +10,7 @@ PLATFORMS, ) from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN +from homeassistant.const import ATTR_MANUFACTURER, ATTR_MODEL, ATTR_NAME from homeassistant.setup import async_setup_component from . import ( @@ -155,9 +156,9 @@ async def test_owserver_setup_valid_device(owproxy, hass, device_id, platform): registry_entry = device_registry.async_get_device({(DOMAIN, device_id)}) assert registry_entry is not None assert registry_entry.identifiers == {(DOMAIN, device_id)} - assert registry_entry.manufacturer == device_info["manufacturer"] - assert registry_entry.name == device_info["name"] - assert registry_entry.model == device_info["model"] + assert registry_entry.manufacturer == device_info[ATTR_MANUFACTURER] + assert registry_entry.name == device_info[ATTR_NAME] + assert registry_entry.model == device_info[ATTR_MODEL] for expected_entity in expected_entities: entity_id = expected_entity["entity_id"] @@ -206,9 +207,9 @@ async def test_onewiredirect_setup_valid_device(hass, device_id): registry_entry = device_registry.async_get_device({(DOMAIN, device_id)}) assert registry_entry is not None assert registry_entry.identifiers == {(DOMAIN, device_id)} - assert registry_entry.manufacturer == device_info["manufacturer"] - assert registry_entry.name == device_info["name"] - assert registry_entry.model == device_info["model"] + assert registry_entry.manufacturer == device_info[ATTR_MANUFACTURER] + assert registry_entry.name == device_info[ATTR_NAME] + assert registry_entry.model == device_info[ATTR_MODEL] for expected_sensor in expected_entities: entity_id = expected_sensor["entity_id"]