core/homeassistant/components/roomba/binary_sensor.py

48 lines
1.3 KiB
Python
Raw Normal View History

Add config_flow for Roomba (#33302) * Add config_flow for roomba * Get options to connect * Fix options in config flow * Fix syntax in config_flow * Remove name (not necessary) * Add bin sensor * Add Battery sensor * Add async_connect * Fix typo * Add Model and Software version * Update Roombapy 1.5.0 * Add validate_input * Add connect and disconnect functions * Remove test config flow * Add variables after loop * Fix translate * Fix typo * Fix state of bin * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Remove invalid auth * Add call function reported_state * Add options reload * Fix tracelog * Set entry_id for config_entry * Fix DOMAIN unsed-import * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Add unique_id for entry * Fix device info * Add config_flow for roomba * Get options to connect * Fix options in config flow * Fix syntax in config_flow * Remove name (not necessary) * Add bin sensor * Add Battery sensor * Add async_connect * Fix typo * Add Model and Software version * Update Roombapy 1.5.0 * Add validate_input * Add connect and disconnect functions * Remove test config flow * Add variables after loop * Fix translate * Fix typo * Fix state of bin * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Remove invalid auth * Add call function reported_state * Add options reload * Fix tracelog * Set entry_id for config_entry * Fix DOMAIN unsed-import * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Add unique_id for entry * Fix device info * syntax for mac (pyupgrade) * Change single key to BLID * Resolve dict conflict * Update homeassistant/components/roomba/binary_sensor.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/sensor.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/.translations/en.json Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/strings.json Co-Authored-By: J. Nick Koston <nick@koston.org> * Add description * Revert "Remove test config flow" This reverts commit 26a89422e89d7c88dd3c0ec3066e607afdc99f09. * Add tests * Remove check if user none * Replace CONF_USERNAME to CONF_BLID (breaking change) * Update test_config_flow.py * Add code owners * Remove CONF_USERNAME (unused) * Add multiple vacuum * Add multiple vacuum * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Fix syntax name * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Remove CONF_PREFIX (unused) * Update homeassistant/components/roomba/sensor.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Add import UNIT_PERCENTAGE * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> Co-authored-by: J. Nick Koston <nick@koston.org>
2020-04-11 15:55:00 +00:00
"""Roomba binary sensor entities."""
import logging
from homeassistant.components.binary_sensor import BinarySensorDevice
from . import roomba_reported_state
from .const import BLID, DOMAIN, ROOMBA_SESSION
from .irobot_base import IRobotEntity
Add config_flow for Roomba (#33302) * Add config_flow for roomba * Get options to connect * Fix options in config flow * Fix syntax in config_flow * Remove name (not necessary) * Add bin sensor * Add Battery sensor * Add async_connect * Fix typo * Add Model and Software version * Update Roombapy 1.5.0 * Add validate_input * Add connect and disconnect functions * Remove test config flow * Add variables after loop * Fix translate * Fix typo * Fix state of bin * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Remove invalid auth * Add call function reported_state * Add options reload * Fix tracelog * Set entry_id for config_entry * Fix DOMAIN unsed-import * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Add unique_id for entry * Fix device info * Add config_flow for roomba * Get options to connect * Fix options in config flow * Fix syntax in config_flow * Remove name (not necessary) * Add bin sensor * Add Battery sensor * Add async_connect * Fix typo * Add Model and Software version * Update Roombapy 1.5.0 * Add validate_input * Add connect and disconnect functions * Remove test config flow * Add variables after loop * Fix translate * Fix typo * Fix state of bin * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Remove invalid auth * Add call function reported_state * Add options reload * Fix tracelog * Set entry_id for config_entry * Fix DOMAIN unsed-import * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Add unique_id for entry * Fix device info * syntax for mac (pyupgrade) * Change single key to BLID * Resolve dict conflict * Update homeassistant/components/roomba/binary_sensor.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/sensor.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/.translations/en.json Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/strings.json Co-Authored-By: J. Nick Koston <nick@koston.org> * Add description * Revert "Remove test config flow" This reverts commit 26a89422e89d7c88dd3c0ec3066e607afdc99f09. * Add tests * Remove check if user none * Replace CONF_USERNAME to CONF_BLID (breaking change) * Update test_config_flow.py * Add code owners * Remove CONF_USERNAME (unused) * Add multiple vacuum * Add multiple vacuum * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Fix syntax name * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Remove CONF_PREFIX (unused) * Update homeassistant/components/roomba/sensor.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Add import UNIT_PERCENTAGE * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> Co-authored-by: J. Nick Koston <nick@koston.org>
2020-04-11 15:55:00 +00:00
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the iRobot Roomba vacuum cleaner."""
domain_data = hass.data[DOMAIN][config_entry.entry_id]
roomba = domain_data[ROOMBA_SESSION]
blid = domain_data[BLID]
status = roomba_reported_state(roomba).get("bin", {})
if "full" in status:
roomba_vac = RoombaBinStatus(roomba, blid)
async_add_entities([roomba_vac], True)
class RoombaBinStatus(IRobotEntity, BinarySensorDevice):
Add config_flow for Roomba (#33302) * Add config_flow for roomba * Get options to connect * Fix options in config flow * Fix syntax in config_flow * Remove name (not necessary) * Add bin sensor * Add Battery sensor * Add async_connect * Fix typo * Add Model and Software version * Update Roombapy 1.5.0 * Add validate_input * Add connect and disconnect functions * Remove test config flow * Add variables after loop * Fix translate * Fix typo * Fix state of bin * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Remove invalid auth * Add call function reported_state * Add options reload * Fix tracelog * Set entry_id for config_entry * Fix DOMAIN unsed-import * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Add unique_id for entry * Fix device info * Add config_flow for roomba * Get options to connect * Fix options in config flow * Fix syntax in config_flow * Remove name (not necessary) * Add bin sensor * Add Battery sensor * Add async_connect * Fix typo * Add Model and Software version * Update Roombapy 1.5.0 * Add validate_input * Add connect and disconnect functions * Remove test config flow * Add variables after loop * Fix translate * Fix typo * Fix state of bin * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Remove invalid auth * Add call function reported_state * Add options reload * Fix tracelog * Set entry_id for config_entry * Fix DOMAIN unsed-import * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/config_flow.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Add unique_id for entry * Fix device info * syntax for mac (pyupgrade) * Change single key to BLID * Resolve dict conflict * Update homeassistant/components/roomba/binary_sensor.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/sensor.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/.translations/en.json Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/strings.json Co-Authored-By: J. Nick Koston <nick@koston.org> * Add description * Revert "Remove test config flow" This reverts commit 26a89422e89d7c88dd3c0ec3066e607afdc99f09. * Add tests * Remove check if user none * Replace CONF_USERNAME to CONF_BLID (breaking change) * Update test_config_flow.py * Add code owners * Remove CONF_USERNAME (unused) * Add multiple vacuum * Add multiple vacuum * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Fix syntax name * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Remove CONF_PREFIX (unused) * Update homeassistant/components/roomba/sensor.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Add import UNIT_PERCENTAGE * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> * Update homeassistant/components/roomba/__init__.py Co-Authored-By: J. Nick Koston <nick@koston.org> Co-authored-by: J. Nick Koston <nick@koston.org>
2020-04-11 15:55:00 +00:00
"""Class to hold Roomba Sensor basic info."""
ICON = "mdi:delete-variant"
@property
def name(self):
"""Return the name of the sensor."""
return f"{self._name} Bin Full"
@property
def unique_id(self):
"""Return the ID of this sensor."""
return f"bin_{self._blid}"
@property
def icon(self):
"""Return the icon of this sensor."""
return self.ICON
@property
def state(self):
"""Return the state of the sensor."""
return roomba_reported_state(self.vacuum).get("bin", {}).get("full", False)