This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+18 -19
View File
@@ -3,13 +3,10 @@ from homeassistant.components import ios
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.icon import icon_for_battery_level
SENSOR_TYPES = {
'level': ['Battery Level', '%'],
'state': ['Battery State', None]
}
SENSOR_TYPES = {"level": ["Battery Level", "%"], "state": ["Battery State", None]}
DEFAULT_ICON_LEVEL = 'mdi:battery'
DEFAULT_ICON_STATE = 'mdi:power-plug'
DEFAULT_ICON_LEVEL = "mdi:battery"
DEFAULT_ICON_STATE = "mdi:power-plug"
def setup_platform(hass, config, add_entities, discovery_info=None):
@@ -21,7 +18,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up iOS from a config entry."""
dev = list()
for device_name, device in ios.devices(hass).items():
for sensor_type in ('level', 'state'):
for sensor_type in ("level", "state"):
dev.append(IOSSensor(sensor_type, device_name, device))
async_add_entities(dev, True)
@@ -43,15 +40,16 @@ class IOSSensor(Entity):
def device_info(self):
"""Return information about the device."""
return {
'identifiers': {
(ios.DOMAIN,
self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_PERMANENT_ID]),
"identifiers": {
(
ios.DOMAIN,
self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_PERMANENT_ID],
)
},
'name': self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_NAME],
'manufacturer': 'Apple',
'model': self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_TYPE],
'sw_version':
self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_SYSTEM_VERSION],
"name": self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_NAME],
"manufacturer": "Apple",
"model": self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_TYPE],
"sw_version": self._device[ios.ATTR_DEVICE][ios.ATTR_DEVICE_SYSTEM_VERSION],
}
@property
@@ -97,8 +95,10 @@ class IOSSensor(Entity):
battery_level = device_battery[ios.ATTR_BATTERY_LEVEL]
charging = True
icon_state = DEFAULT_ICON_STATE
if battery_state in (ios.ATTR_BATTERY_STATE_FULL,
ios.ATTR_BATTERY_STATE_UNPLUGGED):
if battery_state in (
ios.ATTR_BATTERY_STATE_FULL,
ios.ATTR_BATTERY_STATE_UNPLUGGED,
):
charging = False
icon_state = "{}-off".format(DEFAULT_ICON_STATE)
elif battery_state == ios.ATTR_BATTERY_STATE_UNKNOWN:
@@ -108,8 +108,7 @@ class IOSSensor(Entity):
if self.type == "state":
return icon_state
return icon_for_battery_level(battery_level=battery_level,
charging=charging)
return icon_for_battery_level(battery_level=battery_level, charging=charging)
def update(self):
"""Get the latest state of the sensor."""