diff --git a/custom_components/nest_protect/diagnostics.py b/custom_components/nest_protect/diagnostics.py index ee443e20..10553d4e 100644 --- a/custom_components/nest_protect/diagnostics.py +++ b/custom_components/nest_protect/diagnostics.py @@ -12,6 +12,7 @@ from . import HomeAssistantNestProtectData from .const import CONF_COOKIES, CONF_ISSUE_TOKEN, CONF_REFRESH_TOKEN, DOMAIN +from .pynest.const import FULL_NEST_REQUEST TO_REDACT = [ "access_token", @@ -27,6 +28,7 @@ "location", "longitude", "name", + "parameters", "pairing_token", "postal_code", "profile_image_url", @@ -72,7 +74,9 @@ async def async_get_config_entry_diagnostics( data = { "app_launch": dataclasses.asdict( - await client.get_first_data(nest.access_token, nest.userid) + await client.get_first_data( + nest.access_token, nest.userid, request=FULL_NEST_REQUEST + ) ) } diff --git a/custom_components/nest_protect/manifest.json b/custom_components/nest_protect/manifest.json index 637c489c..51868c9c 100644 --- a/custom_components/nest_protect/manifest.json +++ b/custom_components/nest_protect/manifest.json @@ -14,5 +14,5 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/imicknl/ha-nest-protect/issues", "requirements": [], - "version": "0.4.0b5" + "version": "0.4.0b7" } diff --git a/custom_components/nest_protect/pynest/client.py b/custom_components/nest_protect/pynest/client.py index 4fc98592..268223ef 100644 --- a/custom_components/nest_protect/pynest/client.py +++ b/custom_components/nest_protect/pynest/client.py @@ -217,6 +217,10 @@ async def authenticate(self, access_token: str) -> NestResponse: if nest_response.get("error"): _LOGGER.error("Authentication error: %s", nest_response.get("error")) + raise PynestException( + f"{response.status} error while authenticating - {nest_response}." + ) + try: self.nest_session = NestResponse(**nest_response) except Exception as exception: @@ -232,12 +236,12 @@ async def authenticate(self, access_token: str) -> NestResponse: return self.nest_session async def get_first_data( - self, nest_access_token: str, user_id: str + self, nest_access_token: str, user_id: str, request: dict = NEST_REQUEST ) -> FirstDataAPIResponse: """Get first data.""" async with self.session.post( APP_LAUNCH_URL_FORMAT.format(host=self.environment.host, user_id=user_id), - json=NEST_REQUEST, + json=request, headers={ "Authorization": f"Basic {nest_access_token}", "X-nl-user-id": user_id, @@ -250,7 +254,11 @@ async def get_first_data( result["_2fa_enabled"] = result.pop("2fa_enabled") if result.get("error"): - _LOGGER.debug("Received error from Nest service", result) + _LOGGER.debug("Received error from Nest service", await response.text()) + + raise PynestException( + f"{response.status} error while subscribing - {result}" + ) result = FirstDataAPIResponse(**result) @@ -294,7 +302,7 @@ async def subscribe_for_data( "X-nl-protocol-version": str(1), }, ) as response: - _LOGGER.debug("Got data from Nest service (status: %s)", response.status) + _LOGGER.debug("Data received via subscriber (status: %s)", response.status) if response.status == 401: raise NotAuthenticatedException(await response.text()) diff --git a/custom_components/nest_protect/pynest/const.py b/custom_components/nest_protect/pynest/const.py index c108a9ea..56e56ac1 100644 --- a/custom_components/nest_protect/pynest/const.py +++ b/custom_components/nest_protect/pynest/const.py @@ -37,3 +37,32 @@ ], "known_bucket_versions": [], } + +FULL_NEST_REQUEST = { + "known_bucket_types": [ + BucketType.BUCKETS, + BucketType.METADATA, + BucketType.KRYPTONITE, + BucketType.STRUCTURE, + BucketType.TOPAZ, + BucketType.WHERE, + BucketType.USER, + BucketType.DEMAND_RESPONSE, + BucketType.WIDGET_TRACK, + BucketType.OCCUPANCY, + BucketType.MESSAGE, + BucketType.MESSAGE_CENTER, + BucketType.LINK, + BucketType.SAFETY, + BucketType.SAFETY_SUMMARY, + BucketType.DEVICE_ALERT_DIALOG, + BucketType.QUARTZ, + BucketType.TOPAZ_RESOURCE, + BucketType.TRACK, + BucketType.TRIP, + BucketType.STRUCTURE_METADATA, + BucketType.USER, + BucketType.WIDGET_TRACK, + ], + "known_bucket_versions": [], +} diff --git a/custom_components/nest_protect/sensor.py b/custom_components/nest_protect/sensor.py index fd5e34d2..2b19e09b 100644 --- a/custom_components/nest_protect/sensor.py +++ b/custom_components/nest_protect/sensor.py @@ -11,6 +11,7 @@ SensorDeviceClass, SensorEntity, SensorEntityDescription, + SensorStateClass, ) from homeassistant.const import PERCENTAGE, UnitOfTemperature from homeassistant.helpers.entity import EntityCategory @@ -68,6 +69,7 @@ class NestProtectSensorDescription(SensorEntityDescription): native_unit_of_measurement=PERCENTAGE, entity_category=EntityCategory.DIAGNOSTIC, bucket_type=BucketType.KRYPTONITE, + state_class=SensorStateClass.MEASUREMENT, ), # TODO Due to duplicate keys, this sensor is not available yet # NestProtectSensorDescription( @@ -87,6 +89,7 @@ class NestProtectSensorDescription(SensorEntityDescription): native_unit_of_measurement=PERCENTAGE, entity_category=EntityCategory.DIAGNOSTIC, bucket_type=BucketType.TOPAZ, + state_class=SensorStateClass.MEASUREMENT, ), NestProtectSensorDescription( name="Replace By", @@ -101,6 +104,7 @@ class NestProtectSensorDescription(SensorEntityDescription): value_fn=lambda state: round(state, 2), device_class=SensorDeviceClass.TEMPERATURE, native_unit_of_measurement=UnitOfTemperature.CELSIUS, + state_class=SensorStateClass.MEASUREMENT, ), # TODO Add Color Status (gray, green, yellow, red) # TODO Smoke Status (OK, Warning, Emergency) diff --git a/custom_components/nest_protect/strings.json b/custom_components/nest_protect/strings.json index 66bd4779..aadbf00b 100644 --- a/custom_components/nest_protect/strings.json +++ b/custom_components/nest_protect/strings.json @@ -2,12 +2,13 @@ "config": { "step": { "user": { + "description": "Select your Account Type. Most users will need to select Google Account. Field Test is only available for selected testers in the Google Field Test program.", "data": { "account_type": "Account Type" } }, "account_link": { - "description": "Please retrieve your issue_token and cookies manually, following the instructions in the [integration README](https://github.com/iMicknl/ha-nest-protect/tree/beta#retrieving-issue_token-and-cookies) and paste them below.", + "description": "Unfortunately, Google does not provide an official API for this integration. To get it working, you will need to manually retrieve your issue_token and cookies by following the instructions in the integration README (https://github.com/iMicknl/ha-nest-protect/tree/beta#retrieving-issue_token-and-cookies). Please paste them below.", "data": { "issue_token": "[%key:common::config_flow::data::issue_token%]", "cookies": "[%key:common::config_flow::data::cookies%]" diff --git a/custom_components/nest_protect/strings.select.json b/custom_components/nest_protect/strings.select.json deleted file mode 100644 index 1c67f01e..00000000 --- a/custom_components/nest_protect/strings.select.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "state": { - "nest_protect__night_light_brightness": { - "low": "Low", - "medium": "Medium", - "high": "High" - } - } -} \ No newline at end of file diff --git a/custom_components/nest_protect/translations/en.json b/custom_components/nest_protect/translations/en.json index 1989cc40..ebcfa941 100644 --- a/custom_components/nest_protect/translations/en.json +++ b/custom_components/nest_protect/translations/en.json @@ -10,15 +10,16 @@ }, "step": { "user": { + "description": "Select your Account Type. Most users will need to select Google Account. Field Test is only available for selected testers in the Google Field Test program.", "data": { "account_type": "Account Type" } }, "account_link": { - "description": "Please retrieve your issue_token and cookies manually by following the instructions in the [integration README](https://github.com/iMicknl/ha-nest-protect/tree/beta#retrieving-issue_token-and-cookies) and paste them below.", + "description": "Unfortunately, Google does not provide an official API for this integration. To get it working, you will need to manually retrieve your issue_token and cookies by following the instructions in the integration README (https://github.com/iMicknl/ha-nest-protect/tree/beta#retrieving-issue_token-and-cookies). Please paste them below.", "data": { - "issue_token": "issue_token", - "cookies": "cookies" + "issue_token": "Issue_token", + "cookies": "Cookies" } } }