Skip to content

Commit

Permalink
Merge pull request #77 from codyc1515/lint
Browse files Browse the repository at this point in the history
Fix Linting
  • Loading branch information
Arbuzov committed Oct 25, 2023
2 parents f12136a + 0437002 commit d9f472d
Show file tree
Hide file tree
Showing 13 changed files with 622 additions and 241 deletions.
20 changes: 12 additions & 8 deletions custom_components/delonghi_primadonna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
from .const import DOMAIN
from .device import DelongiPrimadonna

PLATFORMS: list[str] = [Platform.BUTTON,
Platform.BINARY_SENSOR,
Platform.SENSOR,
Platform.SELECT,
Platform.SWITCH,
Platform.TEXT,
Platform.DEVICE_TRACKER]
PLATFORMS: list[str] = [
Platform.BUTTON,
Platform.BINARY_SENSOR,
Platform.SENSOR,
Platform.SELECT,
Platform.SWITCH,
Platform.TEXT,
Platform.DEVICE_TRACKER,
]


_LOGGER = logging.getLogger(__name__)
Expand All @@ -35,7 +37,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(
entry, PLATFORMS)
entry,
PLATFORMS
)
if unload_ok:
await hass.data[DOMAIN][entry.unique_id].disconnect()
hass.data[DOMAIN].pop(entry.unique_id)
Expand Down
27 changes: 16 additions & 11 deletions custom_components/delonghi_primadonna/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,29 @@


async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry,
async_add_entities: AddEntitiesCallback):
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback
):
delongh_device = hass.data[DOMAIN][entry.unique_id]
async_add_entities([
DelongiPrimadonnaDescaleSensor(delongh_device, hass),
DelongiPrimadonnaFilterSensor(delongh_device, hass),
DelongiPrimadonnaEnabledSensor(delongh_device, hass),
])
async_add_entities(
[
DelongiPrimadonnaDescaleSensor(delongh_device, hass),
DelongiPrimadonnaFilterSensor(delongh_device, hass),
DelongiPrimadonnaEnabledSensor(delongh_device, hass),
]
)
return True


class DelongiPrimadonnaEnabledSensor(DelonghiDeviceEntity, BinarySensorEntity):
"""
Shows if the device up and running
"""

_attr_device_class = BinarySensorDeviceClass.RUNNING
_attr_name = 'Enabled'

@property
def icon(self) -> str:
"""Return the icon of the device."""
Expand All @@ -49,6 +54,7 @@ class DelongiPrimadonnaDescaleSensor(DelonghiDeviceEntity, BinarySensorEntity):
"""
Shows if the device needs descaling
"""

_attr_device_class = BinarySensorDeviceClass.PROBLEM
_attr_name = 'Descaling'

Expand All @@ -68,12 +74,11 @@ def icon(self):
return result


class DelongiPrimadonnaFilterSensor(
DelonghiDeviceEntity,
BinarySensorEntity):
class DelongiPrimadonnaFilterSensor(DelonghiDeviceEntity, BinarySensorEntity):
"""
Shows if the filter need to be changed
"""

_attr_device_class = BinarySensorDeviceClass.PROBLEM
_attr_name = 'Filter'

Expand Down
14 changes: 7 additions & 7 deletions custom_components/delonghi_primadonna/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import DOMAIN
from .device import AvailableBeverage, DelonghiDeviceEntity, DelongiPrimadonna
from .device import DelonghiDeviceEntity, DelongiPrimadonna


async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry,
async_add_entities: AddEntitiesCallback):
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback
):
delongh_device: DelongiPrimadonna = hass.data[DOMAIN][entry.unique_id]
async_add_entities([
DelongiPrimadonnaPowerButton(delongh_device, hass)
])
async_add_entities([DelongiPrimadonnaPowerButton(delongh_device, hass)])
return True


class DelongiPrimadonnaPowerButton(DelonghiDeviceEntity, ButtonEntity):
"""This button turns on the device"""

_attr_name = 'Turn on ECAM'

async def async_press(self):
self.hass.async_create_task(self.device.power_on())

26 changes: 15 additions & 11 deletions custom_components/delonghi_primadonna/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
STEP_USER_DATA_SCHEMA = voluptuous.Schema(
{
voluptuous.Required(
CONF_NAME,
description={'suggested_value': 'My Precious'}
CONF_NAME, description={'suggested_value': 'My Precious'}
): str,
voluptuous.Required(CONF_MAC): str
voluptuous.Required(CONF_MAC): str,
}
)

Expand All @@ -40,21 +39,24 @@ async def async_step_bluetooth(
_LOGGER.info(
'Discovered Delonghi device: %s %s',
discovery_info.address,
discovery_info.name)
discovery_info.name,
)

await self.async_set_unique_id(discovery_info.address)
self._abort_if_unique_id_configured()

self._schema = voluptuous.Schema(
{
voluptuous.Required(
CONF_NAME,
description={'suggested_value': discovery_info.name}
CONF_NAME, description={
'suggested_value': discovery_info.name
}
): str,
voluptuous.Required(
CONF_MAC,
description={'suggested_value': discovery_info.address}
): str
CONF_MAC, description={
'suggested_value': discovery_info.address
}
): str,
}
)

Expand All @@ -67,12 +69,14 @@ async def async_step_user(

if user_input is None:
return self.async_show_form(
step_id='user', data_schema=self._schema
step_id='user',
data_schema=self._schema
)
else:
await self.async_set_unique_id(user_input[CONF_MAC])
self._abort_if_unique_id_configured()

return self.async_create_entry(
title=user_input[CONF_NAME],
data=user_input)
data=user_input
)
Loading

0 comments on commit d9f472d

Please sign in to comment.