From 2568932c1cd02c8adf63e2e01049e9bc6e7d8a84 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Wed, 26 Aug 2020 10:55:57 +0200 Subject: [PATCH] Bump brother library to version 0.1.15 (#39226) --- homeassistant/components/brother/const.py | 8 ++----- .../components/brother/manifest.json | 2 +- homeassistant/components/brother/sensor.py | 14 +++++++++++++ requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/brother/test_sensor.py | 21 ++++++++++++------- 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/brother/const.py b/homeassistant/components/brother/const.py index 55c9989d60c..98229f5c7a2 100644 --- a/homeassistant/components/brother/const.py +++ b/homeassistant/components/brother/const.py @@ -1,5 +1,5 @@ """Constants for Brother integration.""" -from homeassistant.const import TIME_DAYS, UNIT_PERCENTAGE +from homeassistant.const import UNIT_PERCENTAGE ATTR_BELT_UNIT_REMAINING_LIFE = "belt_unit_remaining_life" ATTR_BLACK_DRUM_COUNTER = "black_drum_counter" @@ -162,9 +162,5 @@ SENSOR_TYPES = { ATTR_LABEL: ATTR_YELLOW_INK_REMAINING.replace("_", " ").title(), ATTR_UNIT: UNIT_PERCENTAGE, }, - ATTR_UPTIME: { - ATTR_ICON: "mdi:timer-outline", - ATTR_LABEL: ATTR_UPTIME.title(), - ATTR_UNIT: TIME_DAYS, - }, + ATTR_UPTIME: {ATTR_ICON: None, ATTR_LABEL: ATTR_UPTIME.title(), ATTR_UNIT: None}, } diff --git a/homeassistant/components/brother/manifest.json b/homeassistant/components/brother/manifest.json index 7f59aaa9c2c..2d3163b125a 100644 --- a/homeassistant/components/brother/manifest.json +++ b/homeassistant/components/brother/manifest.json @@ -3,7 +3,7 @@ "name": "Brother Printer", "documentation": "https://www.home-assistant.io/integrations/brother", "codeowners": ["@bieniu"], - "requirements": ["brother==0.1.14"], + "requirements": ["brother==0.1.15"], "zeroconf": ["_printer._tcp.local."], "config_flow": true, "quality_scale": "platinum" diff --git a/homeassistant/components/brother/sensor.py b/homeassistant/components/brother/sensor.py index d4f389908b1..607a5989abc 100644 --- a/homeassistant/components/brother/sensor.py +++ b/homeassistant/components/brother/sensor.py @@ -1,7 +1,10 @@ """Support for the Brother service.""" +from datetime import timedelta import logging +from homeassistant.const import DEVICE_CLASS_TIMESTAMP from homeassistant.helpers.entity import Entity +from homeassistant.util.dt import utcnow from .const import ( ATTR_BLACK_DRUM_COUNTER, @@ -20,6 +23,7 @@ from .const import ( ATTR_MAGENTA_DRUM_REMAINING_PAGES, ATTR_MANUFACTURER, ATTR_UNIT, + ATTR_UPTIME, ATTR_YELLOW_DRUM_COUNTER, ATTR_YELLOW_DRUM_REMAINING_LIFE, ATTR_YELLOW_DRUM_REMAINING_PAGES, @@ -76,8 +80,18 @@ class BrotherPrinterSensor(Entity): @property def state(self): """Return the state.""" + if self.kind == ATTR_UPTIME: + uptime = utcnow() - timedelta(seconds=self.coordinator.data.get(self.kind)) + return uptime.replace(microsecond=0).isoformat() return self.coordinator.data.get(self.kind) + @property + def device_class(self): + """Return the class of this sensor.""" + if self.kind == ATTR_UPTIME: + return DEVICE_CLASS_TIMESTAMP + return None + @property def device_state_attributes(self): """Return the state attributes.""" diff --git a/requirements_all.txt b/requirements_all.txt index 714e0eaf028..915ced918f3 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -384,7 +384,7 @@ bravia-tv==1.0.6 broadlink==0.14.1 # homeassistant.components.brother -brother==0.1.14 +brother==0.1.15 # homeassistant.components.brottsplatskartan brottsplatskartan==0.0.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index f5e01ba8c77..f4474cb79c6 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -205,7 +205,7 @@ bravia-tv==1.0.6 broadlink==0.14.1 # homeassistant.components.brother -brother==0.1.14 +brother==0.1.15 # homeassistant.components.bsblan bsblan==0.3.7 diff --git a/tests/components/brother/test_sensor.py b/tests/components/brother/test_sensor.py index aeff5a3697d..91109189483 100644 --- a/tests/components/brother/test_sensor.py +++ b/tests/components/brother/test_sensor.py @@ -1,18 +1,19 @@ """Test sensor of Brother integration.""" -from datetime import timedelta +from datetime import datetime, timedelta import json from homeassistant.components.brother.const import UNIT_PAGES from homeassistant.const import ( + ATTR_DEVICE_CLASS, ATTR_ENTITY_ID, ATTR_ICON, ATTR_UNIT_OF_MEASUREMENT, + DEVICE_CLASS_TIMESTAMP, STATE_UNAVAILABLE, - TIME_DAYS, UNIT_PERCENTAGE, ) from homeassistant.setup import async_setup_component -from homeassistant.util.dt import utcnow +from homeassistant.util.dt import UTC, utcnow from tests.async_mock import patch from tests.common import async_fire_time_changed, load_fixture @@ -24,7 +25,12 @@ ATTR_COUNTER = "counter" async def test_sensors(hass): """Test states of the sensors.""" - await init_integration(hass) + test_time = datetime(2019, 11, 11, 9, 10, 32, tzinfo=UTC) + with patch( + "homeassistant.components.brother.sensor.utcnow", return_value=test_time + ): + await init_integration(hass) + registry = await hass.helpers.entity_registry.async_get_registry() state = hass.states.get("sensor.hl_l2340dw_status") @@ -208,9 +214,10 @@ async def test_sensors(hass): state = hass.states.get("sensor.hl_l2340dw_uptime") assert state - assert state.attributes.get(ATTR_ICON) == "mdi:timer-outline" - assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TIME_DAYS - assert state.state == "48" + assert state.attributes.get(ATTR_ICON) is None + assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None + assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TIMESTAMP + assert state.state == "2019-09-24T12:14:56+00:00" entry = registry.async_get("sensor.hl_l2340dw_uptime") assert entry