summaryrefslogtreecommitdiffstats
path: root/Widgets/HVACPage.py
blob: 312f82ba3173d2d6d34ccf4e44b9e83b1b60ea53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""
    Copyright 2023 Suchinton Chakravarty

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at 

        http://www.apache.org/licenses/LICENSE-2.0  
        
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""

import os
import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QListWidget, QSlider, QPushButton

current_dir = os.path.dirname(os.path.abspath(__file__))

# ========================================

sys.path.append(os.path.dirname(current_dir))

from extras.FeedKuksa import FeedKuksa

Form, Base = uic.loadUiType(os.path.join(current_dir, "../ui/HVAC.ui"))

# ========================================

class HVAC_Paths():
    def __init__(self):
        self.leftTemp = "Vehicle.Cabin.HVAC.Station.Row1.Left.Temperature"
        self.leftFanSpeed = "Vehicle.Cabin.HVAC.Station.Row1.Left.FanSpeed"
        self.rightTemp = "Vehicle.Cabin.HVAC.Station.Row1.Right.Temperature"
        self.rightFanSpeed = "Vehicle.Cabin.HVAC.Station.Row1.Right.FanSpeed"

        # temperatureList contains values from 32 to 16 
        self.temperatureList = [str(i) + "°C" for i in range(32, 15, -1)]

class HVACWidget(Base, Form):
    """
    A widget for controlling HVAC settings.

    Inherits from Base and Form.
    """

    def __init__(self, parent=None):
        """
        Initializes the HVACWidget.

        Args:
        - parent: The parent widget. Defaults to None.
        """

        super(self.__class__, self).__init__(parent)
        self.setupUi(self)
        
        self.HVAC = HVAC_Paths()

        self.feed_kuksa = FeedKuksa()
        
        self.leftTempList = self.findChild(QListWidget, "leftTempList")
        self.leftTempList.addItems(self.HVAC.temperatureList)
        self.leftTempList.setCurrentRow(0)
        self.leftTempList.itemClicked.connect(self.leftTempListClicked)
        self.leftTempList.itemSelectionChanged.connect(self.leftTempListClicked)
        self.leftTempList.wheelEvent = lambda event: None

        self.rightTempList = self.findChild(QListWidget, "rightTempList")
        self.rightTempList.addItems(self.HVAC.temperatureList)
        self.rightTempList.setCurrentRow(0)
        self.rightTempList.itemClicked.connect(self.rightTempListClicked)
        self.rightTempList.itemSelectionChanged.connect(self.rightTempListClicked)
        self.rightTempList.wheelEvent = lambda event: None

        self.leftTempUp = self.findChild(QPushButton, "leftTempUp")
        self.leftTempUp.clicked.connect(lambda: self.leftTempList.setCurrentRow(self.leftTempList.currentRow() - 1))

        self.leftTempDown = self.findChild(QPushButton, "leftTempDown")
        self.leftTempDown.clicked.connect(lambda: self.leftTempList.setCurrentRow(self.leftTempList.currentRow() + 1))

        self.rightTempUp = self.findChild(QPushButton, "rightTempUp")
        self.rightTempUp.clicked.connect(lambda: self.rightTempList.setCurrentRow(self.rightTempList.currentRow() - 1))

        self.rightTempDown = self.findChild(QPushButton, "rightTempDown")
        self.rightTempDown.clicked.connect(lambda: self.rightTempList.setCurrentRow(self.rightTempList.currentRow() + 1))

        self.leftFanSpeed_slider = self.findChild(QSlider, "leftFanSpeed_slider")
        self.leftFanSpeed_slider.valueChanged.connect(self.leftFanSpeed_sliderChanged)

        self.rightFanSpeed_slider = self.findChild(QSlider, "rightFanSpeed_slider")
        self.rightFanSpeed_slider.valueChanged.connect(self.rightFanSpeed_sliderChanged)

    def leftTempListClicked(self):
        """
        Handles the event when an item in the left temperature list is clicked.
        Sends the selected temperature value to the feed_kuksa object.
        """

        item = self.leftTempList.currentItem()
        self.leftTempList.scrollToItem(item, 1)
        self.feed_kuksa.send_values(self.HVAC.leftTemp, item.text()[:-2])
        print(item.text())

    def rightTempListClicked(self):
        """
        Handles the event when an item in the right temperature list is clicked.
        Sends the selected temperature value to the feed_kuksa object.
        """

        item = self.rightTempList.currentItem()
        self.rightTempList.scrollToItem(item, 1)
        self.feed_kuksa.send_values(self.HVAC.rightTemp, item.text()[:-2])
        print(item.text())

    def leftFanSpeed_sliderChanged(self):
        """
        Handles the event when the left fan speed slider is changed.
        Sends the selected fan speed value to the feed_kuksa object.
        """

        value = self.leftFanSpeed_slider.value()
        self.feed_kuksa.send_values(self.HVAC.leftFanSpeed, str(value))
        print(value)

    def rightFanSpeed_sliderChanged(self):
        """
        Handles the event when the right fan speed slider is changed.
        Sends the selected fan speed value to the feed_kuksa object.
        """

        value = self.rightFanSpeed_slider.value()
        self.feed_kuksa.send_values(self.HVAC.rightFanSpeed, str(value))
        print(value)

if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    w = HVACWidget()
    w.show()
    sys.exit(app.exec_())