Skip to content

Commit

Permalink
Use constants for device_info in Onewire integration (#53724)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Jul 30, 2021
1 parent 2cbcd5f commit bb7236f
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 117 deletions.
16 changes: 11 additions & 5 deletions homeassistant/components/onewire/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
24 changes: 15 additions & 9 deletions homeassistant/components/onewire/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down
16 changes: 11 additions & 5 deletions homeassistant/components/onewire/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Loading

0 comments on commit bb7236f

Please sign in to comment.