diff --git a/homeassistant/components/azure_devops/__init__.py b/homeassistant/components/azure_devops/__init__.py index 5e3971adcc4..f5537a63291 100644 --- a/homeassistant/components/azure_devops/__init__.py +++ b/homeassistant/components/azure_devops/__init__.py @@ -55,38 +55,22 @@ class AzureDevOpsEntity(Entity): def __init__(self, organization: str, project: str, name: str, icon: str) -> None: """Initialize the Azure DevOps entity.""" - self._name = name - self._icon = icon - self._available = True + self._attr_name = name + self._attr_icon = icon self.organization = organization self.project = project - @property - def name(self) -> str: - """Return the name of the entity.""" - return self._name - - @property - def icon(self) -> str: - """Return the mdi icon of the entity.""" - return self._icon - - @property - def available(self) -> bool: - """Return True if entity is available.""" - return self._available - async def async_update(self) -> None: """Update Azure DevOps entity.""" if await self._azure_devops_update(): - self._available = True + self._attr_available = True else: - if self._available: + if self._attr_available: _LOGGER.debug( "An error occurred while updating Azure DevOps sensor", exc_info=True, ) - self._available = False + self._attr_available = False async def _azure_devops_update(self) -> None: """Update Azure DevOps entity.""" diff --git a/homeassistant/components/azure_devops/sensor.py b/homeassistant/components/azure_devops/sensor.py index 170cd244884..d7589cf5014 100644 --- a/homeassistant/components/azure_devops/sensor.py +++ b/homeassistant/components/azure_devops/sensor.py @@ -71,38 +71,14 @@ class AzureDevOpsSensor(AzureDevOpsDeviceEntity, SensorEntity): unit_of_measurement: str = "", ) -> None: """Initialize Azure DevOps sensor.""" - self._state = None - self._attributes = None - self._available = False - self._unit_of_measurement = unit_of_measurement - self.measurement = measurement + self._attr_unit_of_measurement = unit_of_measurement self.client = client self.organization = organization self.project = project - self.key = key + self._attr_unique_id = "_".join([organization, key]) super().__init__(organization, project, name, icon) - @property - def unique_id(self) -> str: - """Return the unique ID for this sensor.""" - return "_".join([self.organization, self.key]) - - @property - def state(self) -> str: - """Return the state of the sensor.""" - return self._state - - @property - def extra_state_attributes(self) -> object: - """Return the attributes of the sensor.""" - return self._attributes - - @property - def unit_of_measurement(self) -> str: - """Return the unit this state is expressed in.""" - return self._unit_of_measurement - class AzureDevOpsLatestBuildSensor(AzureDevOpsSensor): """Defines a Azure DevOps card count sensor.""" @@ -129,10 +105,10 @@ class AzureDevOpsLatestBuildSensor(AzureDevOpsSensor): ) except aiohttp.ClientError as exception: _LOGGER.warning(exception) - self._available = False + self._attr_available = False return False - self._state = build.build_number - self._attributes = { + self._attr_state = build.build_number + self._attr_extra_state_attributes = { "definition_id": build.definition.id, "definition_name": build.definition.name, "id": build.id, @@ -146,5 +122,5 @@ class AzureDevOpsLatestBuildSensor(AzureDevOpsSensor): "start_time": build.start_time, "finish_time": build.finish_time, } - self._available = True + self._attr_available = True return True