Add UniFi Uptime sensor (#40058)

* Added UniFi Uptime sensor

Added the UniFi uptime data as a sensor. Untested.

* Update sensor.py

Updated code as a result of the tests.

* Changed timestamp format and device class

Converted state to iso timestamp and changed device class to DEVICE_CLASS_TIMESTAMP.

* Updated unit of measurement to None

* Added import

* Update homeassistant/components/unifi/sensor.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Removed whitespace

* Added the uptime sensors option to the config flow

* All the unit tests should be there now

* Whoops

* Fixed translation

* Properly formatted the code

* Flake8 really has angel eyes

* Black should also be satisfied now

* Should have satisfied all static code analysis tools

* Fixed add uptime sensor function

* Fixed overintendation

* Fixed unit tests

* Made a spelling mistake during editing of unit tests

* Test verifies if utc time is correct

* Converted to iso format

* Converted unit test to iso format

* Unit test sensor json had the wrong uptime name

* Added options_updated handler

* Fixed remove sensors unit test

* Update homeassistant/components/unifi/sensor.py

Co-authored-by: Robert Svensson <Kane610@users.noreply.github.com>

* Update homeassistant/components/unifi/sensor.py

Co-authored-by: Robert Svensson <Kane610@users.noreply.github.com>

* Update test_device_tracker.py

Removed uptime from the devices

* Fixed black formatting issue

* I think the code coverage should be good now

* Trying to add the sensors again

* Using signals to hopefully trigger the controller to add them again

* Forgot import

* Sorted components

* fixed isort comments

* Removed CLASS and DEVICE_CLASS

* Added TYPE again

* Removed double underscores

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Robert Svensson <Kane610@users.noreply.github.com>
This commit is contained in:
timkoers 2020-09-18 19:33:37 +02:00 committed by GitHub
parent b25bb78916
commit 46b86f4a2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 163 additions and 15 deletions

View file

@ -4,6 +4,7 @@ import aiounifi
from homeassistant import data_entry_flow
from homeassistant.components.unifi.const import (
CONF_ALLOW_BANDWIDTH_SENSORS,
CONF_ALLOW_UPTIME_SENSORS,
CONF_BLOCK_CLIENT,
CONF_CONTROLLER,
CONF_DETECTION_TIME,
@ -341,7 +342,11 @@ async def test_advanced_option_flow(hass):
assert result["step_id"] == "statistics_sensors"
result = await hass.config_entries.options.async_configure(
result["flow_id"], user_input={CONF_ALLOW_BANDWIDTH_SENSORS: True}
result["flow_id"],
user_input={
CONF_ALLOW_BANDWIDTH_SENSORS: True,
CONF_ALLOW_UPTIME_SENSORS: True,
},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
@ -355,6 +360,7 @@ async def test_advanced_option_flow(hass):
CONF_POE_CLIENTS: False,
CONF_BLOCK_CLIENT: [CLIENTS[0]["mac"]],
CONF_ALLOW_BANDWIDTH_SENSORS: True,
CONF_ALLOW_UPTIME_SENSORS: True,
}