From 2ba8e1030c9b60f9640a004bf3328e17335cec01 Mon Sep 17 00:00:00 2001
From: Aaron Bach <bachya1208@gmail.com>
Date: Thu, 7 Oct 2021 04:40:10 -0600
Subject: [PATCH] Ensure that WattTime is strictly typed (#57130)

---
 .strict-typing                              |  1 +
 homeassistant/components/watttime/sensor.py |  4 ++--
 mypy.ini                                    | 11 +++++++++++
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/.strict-typing b/.strict-typing
index dec244ece15..b5ae496fcf0 100644
--- a/.strict-typing
+++ b/.strict-typing
@@ -122,6 +122,7 @@ homeassistant.components.uptimerobot.*
 homeassistant.components.vacuum.*
 homeassistant.components.vallox.*
 homeassistant.components.water_heater.*
+homeassistant.components.watttime.*
 homeassistant.components.weather.*
 homeassistant.components.websocket_api.*
 homeassistant.components.zodiac.*
diff --git a/homeassistant/components/watttime/sensor.py b/homeassistant/components/watttime/sensor.py
index 6a6d05701c4..50389de35c6 100644
--- a/homeassistant/components/watttime/sensor.py
+++ b/homeassistant/components/watttime/sensor.py
@@ -1,7 +1,7 @@
 """Support for WattTime sensors."""
 from __future__ import annotations
 
-from typing import TYPE_CHECKING
+from typing import TYPE_CHECKING, cast
 
 from homeassistant.components.sensor import (
     STATE_CLASS_MEASUREMENT,
@@ -100,4 +100,4 @@ class RealtimeEmissionsSensor(CoordinatorEntity, SensorEntity):
     @property
     def native_value(self) -> StateType:
         """Return the value reported by the sensor."""
-        return self.coordinator.data[self.entity_description.key]
+        return cast(StateType, self.coordinator.data[self.entity_description.key])
diff --git a/mypy.ini b/mypy.ini
index cc491043c3a..0d4ca87ac64 100644
--- a/mypy.ini
+++ b/mypy.ini
@@ -1353,6 +1353,17 @@ no_implicit_optional = true
 warn_return_any = true
 warn_unreachable = true
 
+[mypy-homeassistant.components.watttime.*]
+check_untyped_defs = true
+disallow_incomplete_defs = true
+disallow_subclassing_any = true
+disallow_untyped_calls = true
+disallow_untyped_decorators = true
+disallow_untyped_defs = true
+no_implicit_optional = true
+warn_return_any = true
+warn_unreachable = true
+
 [mypy-homeassistant.components.weather.*]
 check_untyped_defs = true
 disallow_incomplete_defs = true
-- 
GitLab