prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  `ThermalSensor` doesn't respect `foreground` in `widget_defaults`
  ### The issue:
  
  (reported on Discord/IRC)
  
  ThermalSensor widget doesn't respect foreground colour in widget defaults. This is because the foreground value is copied to `foreground_normal` during `__init__` but this happens before `widget_defaults` are copied to the widget (which happens in `_configure`
  
  ### Required:
  
  - [X] I have searched past issues to see if this bug has already been reported.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `libqtile/widget/sensors.py`
  Content:
  ```
  1 # -*- coding:utf-8 -*-
  2 # Copyright (c) 2012 TiN
  3 # Copyright (c) 2012, 2014 Tycho Andersen
  4 # Copyright (c) 2013 Tao Sauvage
  5 # Copyright (c) 2014-2015 Sean Vig
  6 # Copyright (c) 2014 Adi Sieker
  7 # Copyright (c) 2014 Foster McLane
  8 #
  9 # Permission is hereby granted, free of charge, to any person obtaining a copy
  10 # of this software and associated documentation files (the "Software"), to deal
  11 # in the Software without restriction, including without limitation the rights
  12 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13 # copies of the Software, and to permit persons to whom the Software is
  14 # furnished to do so, subject to the following conditions:
  15 #
  16 # The above copyright notice and this permission notice shall be included in
  17 # all copies or substantial portions of the Software.
  18 #
  19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25 # SOFTWARE.
  26 
  27 import psutil
  28 
  29 from libqtile.widget import base
  30 
  31 
  32 class ThermalSensor(base.InLoopPollText):
  33     """Widget to display temperature sensor information
  34 
  35     For using the thermal sensor widget you need to have lm-sensors installed.
  36     You can get a list of the tag_sensors executing "sensors" in your terminal.
  37     Then you can choose which you want, otherwise it will display the first
  38     available.
  39 
  40     Widget requirements: psutil_.
  41 
  42     .. _psutil: https://pypi.org/project/psutil/
  43     """
  44 
  45     defaults = [
  46         (
  47             "format",
  48             "{temp:.1f}{unit}",
  49             "Display string format. Three options available: "
  50             "``{temp}`` - temperature, "
  51             "``{tag}`` - tag of the temperature sensor, and "
  52             "``{unit}`` - °C or °F",
  53         ),
  54         ("metric", True, "True to use metric/C, False to use imperial/F"),
  55         ("update_interval", 2, "Update interval in seconds"),
  56         ("tag_sensor", None, 'Tag of the temperature sensor. For example: "temp1" or "Core 0"'),
  57         (
  58             "threshold",
  59             70,
  60             "If the current temperature value is above, "
  61             "then change to foreground_alert colour",
  62         ),
  63         ("foreground_alert", "ff0000", "Foreground colour alert"),
  64     ]
  65 
  66     def __init__(self, **config):
  67         base.InLoopPollText.__init__(self, **config)
  68         self.add_defaults(ThermalSensor.defaults)
  69         temp_values = self.get_temp_sensors()
  70         self.foreground_normal = self.foreground
  71 
  72         if temp_values is None:
  73             self.data = "sensors command not found"
  74         elif len(temp_values) == 0:
  75             self.data = "Temperature sensors not found"
  76         elif self.tag_sensor is None:
  77             for k in temp_values:
  78                 self.tag_sensor = k
  79                 break
  80 
  81     def _configure(self, qtile, bar):
  82         self.unit = "°C" if self.metric else "°F"
  83         base.InLoopPollText._configure(self, qtile, bar)
  84 
  85     def get_temp_sensors(self):
  86         """
  87         Reads temperatures from sys-fs via psutil.
  88         Output will be read Fahrenheit if user has specified it to be.
  89         """
  90 
  91         temperature_list = {}
  92         temps = psutil.sensors_temperatures(fahrenheit=not self.metric)
  93         empty_index = 0
  94         for kernel_module in temps:
  95             for sensor in temps[kernel_module]:
  96                 label = sensor.label
  97                 if not label:
  98                     label = "{}-{}".format(
  99                         kernel_module if kernel_module else "UNKNOWN", str(empty_index)
  100                     )
  101                     empty_index += 1
  102                 temperature_list[label] = sensor.current
  103 
  104         return temperature_list
  105 
  106     def poll(self):
  107         temp_values = self.get_temp_sensors()
  108 
  109         # Temperature not available
  110         if (temp_values is None) or (self.tag_sensor not in temp_values):
  111             return "N/A"
  112 
  113         temp_value = temp_values.get(self.tag_sensor)
  114         if temp_value > self.threshold:
  115             self.layout.colour = self.foreground_alert
  116         else:
  117             self.layout.colour = self.foreground_normal
  118 
  119         val = dict(temp=temp_value, tag=self.tag_sensor, unit=self.unit)
  120         return self.format.format(**val)
  121
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/libqtile/widget/sensors.py b/libqtile/widget/sensors.py
  --- a/libqtile/widget/sensors.py
  +++ b/libqtile/widget/sensors.py
  @@ -67,7 +67,6 @@
           base.InLoopPollText.__init__(self, **config)
           self.add_defaults(ThermalSensor.defaults)
           temp_values = self.get_temp_sensors()
  -        self.foreground_normal = self.foreground
   
           if temp_values is None:
               self.data = "sensors command not found"
  @@ -81,6 +80,7 @@
       def _configure(self, qtile, bar):
           self.unit = "°C" if self.metric else "°F"
           base.InLoopPollText._configure(self, qtile, bar)
  +        self.foreground_normal = self.foreground
   
       def get_temp_sensors(self):
           """
  
verification_info: {"golden_diff": "diff --git a/libqtile/widget/sensors.py b/libqtile/widget/sensors.py\n--- a/libqtile/widget/sensors.py\n+++ b/libqtile/widget/sensors.py\n@@ -67,7 +67,6 @@\n         base.InLoopPollText.__init__(self, **config)\n         self.add_defaults(ThermalSensor.defaults)\n         temp_values = self.get_temp_sensors()\n-        self.foreground_normal = self.foreground\n \n         if temp_values is None:\n             self.data = \"sensors command not found\"\n@@ -81,6 +80,7 @@\n     def _configure(self, qtile, bar):\n         self.unit = \"\u00b0C\" if self.metric else \"\u00b0F\"\n         base.InLoopPollText._configure(self, qtile, bar)\n+        self.foreground_normal = self.foreground\n \n     def get_temp_sensors(self):\n         \"\"\"\n", "issue": "`ThermalSensor` doesn't respect `foreground` in `widget_defaults`\n### The issue:\n\n(reported on Discord/IRC)\r\n\r\nThermalSensor widget doesn't respect foreground colour in widget defaults. This is because the foreground value is copied to `foreground_normal` during `__init__` but this happens before `widget_defaults` are copied to the widget (which happens in `_configure`\n\n### Required:\n\n- [X] I have searched past issues to see if this bug has already been reported.\n", "before_files": [{"content": "# -*- coding:utf-8 -*-\n# Copyright (c) 2012 TiN\n# Copyright (c) 2012, 2014 Tycho Andersen\n# Copyright (c) 2013 Tao Sauvage\n# Copyright (c) 2014-2015 Sean Vig\n# Copyright (c) 2014 Adi Sieker\n# Copyright (c) 2014 Foster McLane\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n# SOFTWARE.\n\nimport psutil\n\nfrom libqtile.widget import base\n\n\nclass ThermalSensor(base.InLoopPollText):\n    \"\"\"Widget to display temperature sensor information\n\n    For using the thermal sensor widget you need to have lm-sensors installed.\n    You can get a list of the tag_sensors executing \"sensors\" in your terminal.\n    Then you can choose which you want, otherwise it will display the first\n    available.\n\n    Widget requirements: psutil_.\n\n    .. _psutil: https://pypi.org/project/psutil/\n    \"\"\"\n\n    defaults = [\n        (\n            \"format\",\n            \"{temp:.1f}{unit}\",\n            \"Display string format. Three options available: \"\n            \"``{temp}`` - temperature, \"\n            \"``{tag}`` - tag of the temperature sensor, and \"\n            \"``{unit}`` - \u00b0C or \u00b0F\",\n        ),\n        (\"metric\", True, \"True to use metric/C, False to use imperial/F\"),\n        (\"update_interval\", 2, \"Update interval in seconds\"),\n        (\"tag_sensor\", None, 'Tag of the temperature sensor. For example: \"temp1\" or \"Core 0\"'),\n        (\n            \"threshold\",\n            70,\n            \"If the current temperature value is above, \"\n            \"then change to foreground_alert colour\",\n        ),\n        (\"foreground_alert\", \"ff0000\", \"Foreground colour alert\"),\n    ]\n\n    def __init__(self, **config):\n        base.InLoopPollText.__init__(self, **config)\n        self.add_defaults(ThermalSensor.defaults)\n        temp_values = self.get_temp_sensors()\n        self.foreground_normal = self.foreground\n\n        if temp_values is None:\n            self.data = \"sensors command not found\"\n        elif len(temp_values) == 0:\n            self.data = \"Temperature sensors not found\"\n        elif self.tag_sensor is None:\n            for k in temp_values:\n                self.tag_sensor = k\n                break\n\n    def _configure(self, qtile, bar):\n        self.unit = \"\u00b0C\" if self.metric else \"\u00b0F\"\n        base.InLoopPollText._configure(self, qtile, bar)\n\n    def get_temp_sensors(self):\n        \"\"\"\n        Reads temperatures from sys-fs via psutil.\n        Output will be read Fahrenheit if user has specified it to be.\n        \"\"\"\n\n        temperature_list = {}\n        temps = psutil.sensors_temperatures(fahrenheit=not self.metric)\n        empty_index = 0\n        for kernel_module in temps:\n            for sensor in temps[kernel_module]:\n                label = sensor.label\n                if not label:\n                    label = \"{}-{}\".format(\n                        kernel_module if kernel_module else \"UNKNOWN\", str(empty_index)\n                    )\n                    empty_index += 1\n                temperature_list[label] = sensor.current\n\n        return temperature_list\n\n    def poll(self):\n        temp_values = self.get_temp_sensors()\n\n        # Temperature not available\n        if (temp_values is None) or (self.tag_sensor not in temp_values):\n            return \"N/A\"\n\n        temp_value = temp_values.get(self.tag_sensor)\n        if temp_value > self.threshold:\n            self.layout.colour = self.foreground_alert\n        else:\n            self.layout.colour = self.foreground_normal\n\n        val = dict(temp=temp_value, tag=self.tag_sensor, unit=self.unit)\n        return self.format.format(**val)\n", "path": "libqtile/widget/sensors.py"}], "after_files": [{"content": "# -*- coding:utf-8 -*-\n# Copyright (c) 2012 TiN\n# Copyright (c) 2012, 2014 Tycho Andersen\n# Copyright (c) 2013 Tao Sauvage\n# Copyright (c) 2014-2015 Sean Vig\n# Copyright (c) 2014 Adi Sieker\n# Copyright (c) 2014 Foster McLane\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to deal\n# in the Software without restriction, including without limitation the rights\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n# copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n# SOFTWARE.\n\nimport psutil\n\nfrom libqtile.widget import base\n\n\nclass ThermalSensor(base.InLoopPollText):\n    \"\"\"Widget to display temperature sensor information\n\n    For using the thermal sensor widget you need to have lm-sensors installed.\n    You can get a list of the tag_sensors executing \"sensors\" in your terminal.\n    Then you can choose which you want, otherwise it will display the first\n    available.\n\n    Widget requirements: psutil_.\n\n    .. _psutil: https://pypi.org/project/psutil/\n    \"\"\"\n\n    defaults = [\n        (\n            \"format\",\n            \"{temp:.1f}{unit}\",\n            \"Display string format. Three options available: \"\n            \"``{temp}`` - temperature, \"\n            \"``{tag}`` - tag of the temperature sensor, and \"\n            \"``{unit}`` - \u00b0C or \u00b0F\",\n        ),\n        (\"metric\", True, \"True to use metric/C, False to use imperial/F\"),\n        (\"update_interval\", 2, \"Update interval in seconds\"),\n        (\"tag_sensor\", None, 'Tag of the temperature sensor. For example: \"temp1\" or \"Core 0\"'),\n        (\n            \"threshold\",\n            70,\n            \"If the current temperature value is above, \"\n            \"then change to foreground_alert colour\",\n        ),\n        (\"foreground_alert\", \"ff0000\", \"Foreground colour alert\"),\n    ]\n\n    def __init__(self, **config):\n        base.InLoopPollText.__init__(self, **config)\n        self.add_defaults(ThermalSensor.defaults)\n        temp_values = self.get_temp_sensors()\n\n        if temp_values is None:\n            self.data = \"sensors command not found\"\n        elif len(temp_values) == 0:\n            self.data = \"Temperature sensors not found\"\n        elif self.tag_sensor is None:\n            for k in temp_values:\n                self.tag_sensor = k\n                break\n\n    def _configure(self, qtile, bar):\n        self.unit = \"\u00b0C\" if self.metric else \"\u00b0F\"\n        base.InLoopPollText._configure(self, qtile, bar)\n        self.foreground_normal = self.foreground\n\n    def get_temp_sensors(self):\n        \"\"\"\n        Reads temperatures from sys-fs via psutil.\n        Output will be read Fahrenheit if user has specified it to be.\n        \"\"\"\n\n        temperature_list = {}\n        temps = psutil.sensors_temperatures(fahrenheit=not self.metric)\n        empty_index = 0\n        for kernel_module in temps:\n            for sensor in temps[kernel_module]:\n                label = sensor.label\n                if not label:\n                    label = \"{}-{}\".format(\n                        kernel_module if kernel_module else \"UNKNOWN\", str(empty_index)\n                    )\n                    empty_index += 1\n                temperature_list[label] = sensor.current\n\n        return temperature_list\n\n    def poll(self):\n        temp_values = self.get_temp_sensors()\n\n        # Temperature not available\n        if (temp_values is None) or (self.tag_sensor not in temp_values):\n            return \"N/A\"\n\n        temp_value = temp_values.get(self.tag_sensor)\n        if temp_value > self.threshold:\n            self.layout.colour = self.foreground_alert\n        else:\n            self.layout.colour = self.foreground_normal\n\n        val = dict(temp=temp_value, tag=self.tag_sensor, unit=self.unit)\n        return self.format.format(**val)\n", "path": "libqtile/widget/sensors.py"}]}