Skip to content

Commit

Permalink
Fix the "name" in devices
Browse files Browse the repository at this point in the history
  • Loading branch information
garbled1 committed Nov 26, 2020
1 parent 4f070ec commit 6266674
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
5 changes: 3 additions & 2 deletions custom_components/balboa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ class BalboaEntity(Entity):
accessors.
"""

def __init__(self, hass, client, name):
def __init__(self, hass, client, name, entry):
"""Initialize the spa."""
self.hass = hass
self._client = client
self._name = name
self._entry = entry

async def async_added_to_hass(self) -> None:
"""Set up a listener for the entity."""
Expand Down Expand Up @@ -154,7 +155,7 @@ def device_info(self) -> Dict[str, Any]:
"""Return device information for this sensor."""
return {
"identifiers": {(DOMAIN, self._client.get_macaddr())},
"name": self._name,
"name": self._entry.data[CONF_NAME],
"manufacturer": 'Balboa Water Group',
"model": self._client.get_model_name(),
"sw_version": self._client.get_ssid()
Expand Down
14 changes: 8 additions & 6 deletions custom_components/balboa/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,23 @@ async def async_setup_entry(hass, entry, async_add_entities):
name = entry.data[CONF_NAME]
devs = []

devs.append(BalboaSpaBinarySensor(hass, spa, f"{name}-filter1", "filter1"))
devs.append(BalboaSpaBinarySensor(hass, spa, f"{name}-filter2", "filter2"))
devs.append(BalboaSpaBinarySensor(hass, spa, f"{name}-filter1",
entry, "filter1"))
devs.append(BalboaSpaBinarySensor(hass, spa, f"{name}-filter2",
entry, "filter2"))

if spa.have_circ_pump():
devs.append(BalboaSpaBinarySensor(hass, spa, f"{name}-circ_pump", "circ_pump"))
devs.append(BalboaSpaBinarySensor(hass, spa, f"{name}-circ_pump",
entry, "circ_pump"))
async_add_entities(devs, True)


class BalboaSpaBinarySensor(BalboaEntity, BinarySensorEntity):
"""Representation of a Balboa Spa binary sensor device."""

def __init__(self, hass, client, name, bsensor_key):
def __init__(self, hass, client, name, entry, bsensor_key):
"""Initialize the binary sensor."""
super().__init__(hass, client, name)
super().__init__(hass, client, name, entry)
self.bsensor_key = bsensor_key

@property
Expand Down Expand Up @@ -67,4 +70,3 @@ def icon(self):
if "circ_pump" in self.bsensor_key:
return "mdi:water-pump" if self.is_on else "mdi:water-pump-off"
return "mdi:sync" if self.is_on else "mdi:sync-off"

2 changes: 1 addition & 1 deletion custom_components/balboa/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
"""Set up the spa climate device."""
spa = hass.data[BALBOA_DOMAIN][entry.entry_id]
name = entry.data[CONF_NAME]
async_add_entities([BalboaSpaClimate(hass, spa, name)], True)
async_add_entities([BalboaSpaClimate(hass, spa, name, entry)], True)


class BalboaSpaClimate(BalboaEntity, ClimateEntity):
Expand Down
7 changes: 4 additions & 3 deletions custom_components/balboa/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ async def async_setup_entry(hass, entry, async_add_entities):

for idx in enumerate(pumps):
if pumps[idx[0]]:
devs.append(BalboaSpaPump(hass, spa, f"{name}-pump{idx[0] + 1}", idx[0]))
devs.append(BalboaSpaPump(hass, spa, f"{name}-pump{idx[0] + 1}",
entry, idx[0]))

async_add_entities(devs, True)


class BalboaSpaPump(BalboaEntity, FanEntity):
"""Representation of a Balboa Spa pump device."""

def __init__(self, hass, client, name, pump):
def __init__(self, hass, client, name, entry, pump):
"""Initialize the pump."""
super().__init__(hass, client, name)
super().__init__(hass, client, name, entry)
self.pump = pump
_LOGGER.debug("Creating pump #%d", pump)

Expand Down
14 changes: 7 additions & 7 deletions custom_components/balboa/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ async def async_setup_entry(hass, entry, async_add_entities):

lights = spa.get_light_list()
if lights[0]:
devs.append(BalboaSpaSwitch(hass, spa, f"{name}-light1", "light1"))
devs.append(BalboaSpaSwitch(hass, spa, f"{name}-light1", entry, "light1"))
if lights[1]:
devs.append(BalboaSpaSwitch(hass, spa, f"{name}-light2", "light2"))
devs.append(BalboaSpaSwitch(hass, spa, f"{name}-light2", entry, "light2"))
auxs = spa.get_aux_list()
if auxs[0]:
devs.append(BalboaSpaSwitch(hass, spa, f"{name}-aux1", "aux1"))
devs.append(BalboaSpaSwitch(hass, spa, f"{name}-aux1", entry, "aux1"))
if auxs[1]:
devs.append(BalboaSpaSwitch(hass, spa, f"{name}-aux2", "aux2"))
devs.append(BalboaSpaSwitch(hass, spa, f"{name}-aux2", entry, "aux2"))
if spa.have_mister():
devs.append(BalboaSpaSwitch(hass, spa, f"{name}-mister", "mister"))
devs.append(BalboaSpaSwitch(hass, spa, f"{name}-mister", entry, "mister"))

async_add_entities(devs, True)


class BalboaSpaSwitch(BalboaEntity, SwitchEntity):
"""Representation of a Balboa Spa switch device."""

def __init__(self, hass, client, name, switch_key):
def __init__(self, hass, client, name, entry, switch_key):
"""Initialize the switch."""
super().__init__(hass, client, name)
super().__init__(hass, client, name, entry)
self.switch_key = switch_key
self.getdata = {
"light1": self._client.get_light,
Expand Down

0 comments on commit 6266674

Please sign in to comment.