コード例 #1
0
ファイル: sensor.py プロジェクト: uzbekdev1/core-2
    def get_data(self):
        """Get data from the device.

        Flatten dictionary to map device to map of device data.

        """

        data = {}
        try:
            data = tank_monitor.get_device_data(self._token, self.device)
        except requests.exceptions.HTTPError as http_error:
            if (http_error.response.status_code == requests.codes.unauthorized  # pylint: disable=no-member
                    or http_error.response.status_code
                    == requests.codes.bad_request  # pylint: disable=no-member
                ):
                _LOGGER.info("Getting new token")
                self._token = auth.get_token(self._email,
                                             self._password,
                                             force=True)
                data = tank_monitor.get_device_data(self._token, self.device)
            else:
                raise http_error
        data.update(data.pop("device", {}))
        data.update(data.pop("lastReading", {}))
        return data
コード例 #2
0
ファイル: sensor.py プロジェクト: rikroe/core
def setup_platform(
    hass: HomeAssistant,
    config: ConfigType,
    add_entities: AddEntitiesCallback,
    discovery_info: DiscoveryInfoType | None = None,
) -> None:
    """Set up the Tank Utility sensor."""

    email = config[CONF_EMAIL]
    password = config[CONF_PASSWORD]
    devices = config[CONF_DEVICES]

    try:
        token = auth.get_token(email, password)
    except requests.exceptions.HTTPError as http_error:
        if (
            http_error.response.status_code
            == requests.codes.unauthorized  # pylint: disable=no-member
        ):
            _LOGGER.error("Invalid credentials")
            return

    all_sensors = []
    for device in devices:
        sensor = TankUtilitySensor(email, password, token, device)
        all_sensors.append(sensor)
    add_entities(all_sensors, True)
コード例 #3
0
ファイル: tank_utility.py プロジェクト: sara0871/master.zip
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Tank Utility sensor."""
    from tank_utility import auth
    email = config.get(CONF_EMAIL)
    password = config.get(CONF_PASSWORD)
    devices = config.get(CONF_DEVICES)

    try:
        token = auth.get_token(email, password)
    except requests.exceptions.HTTPError as http_error:
        if (http_error.response.status_code == requests.codes.unauthorized):  # pylint: disable=no-member
            _LOGGER.error("Invalid credentials")
            return

    all_sensors = []
    for device in devices:
        sensor = TankUtilitySensor(email, password, token, device)
        all_sensors.append(sensor)
    add_devices(all_sensors, True)
コード例 #4
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up the Tank Utility sensor."""
    from tank_utility import auth
    email = config.get(CONF_EMAIL)
    password = config.get(CONF_PASSWORD)
    devices = config.get(CONF_DEVICES)

    try:
        token = auth.get_token(email, password)
    except requests.exceptions.HTTPError as http_error:
        if (http_error.response.status_code ==
                requests.codes.unauthorized):  # pylint: disable=no-member
            _LOGGER.error("Invalid credentials")
            return

    all_sensors = []
    for device in devices:
        sensor = TankUtilitySensor(email, password, token, device)
        all_sensors.append(sensor)
    add_devices(all_sensors, True)
コード例 #5
0
    def get_data(self):
        """Get data from the device.

        Flatten dictionary to map device to map of device data.

        """
        from tank_utility import auth, device
        data = {}
        try:
            data = device.get_device_data(self._token, self.device)
        except requests.exceptions.HTTPError as http_error:
            if (http_error.response.status_code ==
                    requests.codes.unauthorized):  # pylint: disable=no-member
                _LOGGER.info("Getting new token")
                self._token = auth.get_token(self._email, self._password,
                                             force=True)
                data = device.get_device_data(self._token, self.device)
            else:
                raise http_error
        data.update(data.pop("device", {}))
        data.update(data.pop("lastReading", {}))
        return data